51 Java OOPs Interview Questions and Answers PDF 2025

Java OOPs Interview Questions PDF

Object-Oriented Programming is crucial for Java developer interviews, whether you’re targeting backend, software engineer, or architect roles. Most candidates memorize basic OOP definitions but struggle explaining real-world applications and design principles.

This guide goes beyond textbook answers. We’ve curated challenging interview questions that top companies actually use, focusing on three areas: conceptual mastery of OOP principles, real-world coding scenarios, and best practices with trade-offs. Each question includes practical examples, code snippets, and explanations that show why concepts matter in professional development.

Java OOPs Interview Questions and Answers for Freshers

Que 1. What are the four main principles of OOP in Java?

The four core principles are:

  • Encapsulation: Binding data and methods into a single unit (class).
  • Abstraction: Hiding complex implementation details and showing only the necessary features.
  • Inheritance: Allows one class to inherit the properties and methods of another.
  • Polymorphism: Enables one task to be performed in multiple ways (method overloading/overriding).

Que 2. How does encapsulation work in Java?

Encapsulation is achieved using access modifiers (private, public, etc.) and by providing getter and setter methods to access and modify private fields.

public class Student {
    private String name;

    public void setName(String n) {
        name = n;
    }

    public String getName() {
        return name;
    }
}

Que 3. What is the use of the super keyword in Java?

The super keyword is used to:

  • Access methods or variables of a parent class.
  • Call the parent class constructor from a subclass.

Que 4. What is method overloading in Java?

Method overloading allows a class to have more than one method with the same name but different parameter types or count.

void display(int a) {}
void display(String a) {}

Que 5. What is method overriding?

Method overriding occurs when a subclass provides a specific implementation for a method already defined in its superclass.

Que 6. What is the difference between overloading and overriding?

FeatureOverloadingOverriding
ClassSame classSubclass
Method SignatureMust be differentMust be the same
Runtime/CompileCompile-timeRuntime
InheritanceNot requiredRequired

Que 7. What is abstraction in Java?

Abstraction is the process of hiding internal implementation details and showing only the essential features. It can be achieved using abstract classes and interfaces.

Que 8. How is an abstract class different from an interface?

An abstract class can have method implementations and member variables, while an interface only allows method declarations (Java 8+ allows default methods).

Que 9. Can we create an object of an abstract class?

No, you cannot instantiate an abstract class directly. It must be extended by a subclass that provides implementations for the abstract methods.

Que 10. What is inheritance in Java?

Inheritance allows a class (subclass) to inherit properties and behaviors (methods) from another class (superclass), promoting code reuse and hierarchy.

Que 11. What is the difference between this and super?

  • this: Refers to the current class instance.
  • super: Refers to the immediate parent class instance.

Que 12. What are constructors in Java?

Constructors are special methods used to initialize objects. They have the same name as the class and no return type.

Que 13. What is constructor overloading?

Constructor overloading means having multiple constructors in a class with different parameter lists.

public class Car {
    Car() {}
    Car(String model) {}
}

Que 14. What is static polymorphism?

Static polymorphism (compile-time polymorphism) is achieved through method overloading. The method to be executed is determined at compile time.

Que 15. What is dynamic polymorphism?

Dynamic polymorphism (runtime polymorphism) is achieved through method overriding. The method call is resolved at runtime using the object type.

Que 16. Can a class implement multiple interfaces?

Yes, Java supports multiple interface implementations using commas to separate them:

class MyClass implements Interface1, Interface2 {}

Que 17. What are the access modifiers in Java?

  • public: Accessible everywhere
  • private: Accessible only within the class
  • protected: Accessible within package and subclass
  • Default (no modifier): Accessible within the same package

Que 18. What is final keyword in Java?

final can be used with variables (constants), methods (cannot override), and classes (cannot inherit).

Que 19. What is the difference between class and object?

  • Class: Blueprint or template.
  • Object: An instance of a class that occupies memory.

Que 20. What is the role of the instanceof operator?

The instanceof operator checks whether an object is an instance of a specific class or subclass:

if (obj instanceof Animal) {
    // Do something
}
Java OOPs Interview Questions Freshers

Also Check: OOPs Interview Questions and Answers PDF

Java OOPs Interview Questions and Answers for Experienced

Que 21. How does Java implement runtime polymorphism internally?

Java implements runtime polymorphism through method overriding and dynamic method dispatch. At runtime, the JVM determines the appropriate method to invoke using the actual object type rather than the reference type.

Que 22. How does the JVM resolve method calls in polymorphism?

JVM uses a technique called dynamic method dispatch. It maintains a method table (vtable) for every class and resolves overridden method calls based on the actual object type at runtime.

Que 23. What is the difference between interface default methods and abstract class methods?

FeatureInterface Default MethodAbstract Class Method
ImplementationAllowed from Java 8Always allowed
Multiple InheritanceHandled with careNot supported
ConstructorsNot allowedAllowed
Use CaseFunctional extensionBase class abstraction

Que 24. Can you explain Liskov Substitution Principle in Java with an example?

Liskov Substitution Principle (LSP) states that objects of a subclass should be replaceable with objects of the superclass without affecting the program’s correctness.

class Bird {
   void fly() {}
}

class Ostrich extends Bird {
   void fly() {
       throw new UnsupportedOperationException("Ostrich can't fly");
   }
}

This violates LSP. The design should avoid such contradictions in subclass behavior.

Que 25. What is object slicing in Java? How does it relate to inheritance?

Java does not support object slicing like C++, but similar issues can occur if subclass-specific behavior is accessed via a superclass reference without proper casting or dynamic checks.

Que 26. What are inner classes in Java and how are they useful in OOP?

Inner classes are classes defined inside another class. They help logically group classes, enhance encapsulation, and can access outer class members including private fields.

Que 27. How can reflection break encapsulation in OOP?

Reflection in Java allows access to private fields and methods using setAccessible(true), which can violate encapsulation and lead to insecure or unpredictable behavior.

Que 28. What are design patterns that support OOP principles in Java?

Common OOP-aligned design patterns include:

  • Factory (encapsulation and abstraction)
  • Singleton (encapsulation)
  • Strategy (polymorphism)
  • Observer (abstraction and decoupling)

Que 29. What is the difference between aggregation and composition in Java?

FeatureAggregationComposition
OwnershipWeak (has-a)Strong (owns-a)
LifecycleIndependentDependent
ExampleDepartment has EmployeesHouse has Rooms

Que 30. Can private methods be overridden?

No, private methods are not visible to subclasses, hence they cannot be overridden. However, a method with the same name in the subclass is a new method, not an override.

Que 31. What is method hiding and how is it different from overriding?

Method hiding occurs when a static method in the subclass has the same signature as one in the parent. It does not participate in polymorphism.

class Parent {
    static void show() {}
}
class Child extends Parent {
    static void show() {}
}

Que 32. How does Java handle multiple inheritance in interfaces?

Java allows a class to implement multiple interfaces. If two interfaces have default methods with the same signature, the implementing class must override it to resolve the conflict.

Que 33. Explain covariance and contravariance in Java.

  • Covariance: Allows a method to return a subclass type.
  • Contravariance: Applies to generic method parameters, where supertype parameters are allowed.
class A {}
class B extends A {}

A getObject() { return new B(); } // Covariant return type

Que 34. What is the role of access modifiers in inheritance?

  • private: Not inherited
  • default: Inherited within the same package
  • protected: Inherited in subclasses even across packages
  • public: Inherited everywhere

Que 35. How does the final keyword affect OOP?

  • final class: Cannot be extended
  • final method: Cannot be overridden
  • final variable: Cannot be reassigned

Que 36. How can interfaces achieve multiple inheritance in Java?

Interfaces allow multiple inheritance by declaring method signatures only. With Java 8+, they can include default methods, which must be resolved by overriding if a conflict occurs.

Que 37. What is a marker interface in Java?

A marker interface is an empty interface used to convey metadata to the JVM or frameworks. Example: Serializable, Cloneable.

Que 38. How does Java support abstraction without abstract classes?

Using interfaces, Java achieves 100% abstraction (until Java 8) since interfaces can’t have method bodies (except default/static methods).

Que 39. What are the common pitfalls in using inheritance?

  • Tight coupling
  • Inappropriate use of “is-a”
  • Increased fragility of code
  • Violation of Liskov Principle

Que 40. How would you refactor deep inheritance hierarchies?

Prefer composition over inheritance by breaking large class hierarchies into smaller, reusable classes and using interfaces to share behavior.

Core Java OOPs Interview Questions and Answers

Que 41. What are the key OOP principles implemented in Java?

Java implements the four core OOP principles:

  • Encapsulation: Bundling data and methods within a class
  • Abstraction: Hiding internal implementation details using interfaces or abstract classes
  • Inheritance: Enabling code reuse through hierarchical relationships
  • Polymorphism: Allowing objects to be treated as instances of their parent class

Que 42. How does Java handle object cloning, and what are the challenges?

Java uses the Cloneable interface and Object.clone() method. However, it performs shallow cloning by default. Deep cloning must be implemented manually, which can be error-prone.

class Person implements Cloneable {
   String name;
   Address address;
   public Object clone() throws CloneNotSupportedException {
       Person cloned = (Person) super.clone();
       cloned.address = new Address(this.address.city);
       return cloned;
   }
}

Que 43. What is the role of abstract classes in Java OOP?

Abstract classes define a partial blueprint. They can have:

  • Abstract methods (without body)
  • Concrete methods
  • Constructors
  • Instance variables

They are useful when you want base functionality with the flexibility of subclass extension.

Que 44. How does Java resolve the diamond problem with interfaces?

Java avoids the diamond problem by:

  • Not supporting multiple inheritance with classes
  • For interfaces (Java 8+), if two interfaces provide the same default method, the class must override it explicitly to resolve ambiguity.

Que 45. How is method overloading different from method overriding?

FeatureMethod OverloadingMethod Overriding
DefinitionSame method name, different parametersSame method name and parameters
Compile-time/runtimeCompile-timeRuntime
Inheritance requiredNoYes

Que 46. What are anonymous inner classes and their OOP relevance?

Anonymous inner classes allow one-time implementation of interfaces or subclassing. They help maintain concise code and are used in event handling or when behavior needs to be injected dynamically.

Runnable r = new Runnable() {
   public void run() {
       System.out.println("Running");
   }
};

Que 47. What are some signs of poor object-oriented design in Java?

  • Violations of SRP or SOLID principles
  • Deep inheritance chains
  • Inappropriate use of static methods
  • Tight coupling and poor encapsulation

Que 48. How does Java use interfaces to achieve abstraction and loose coupling?

Interfaces define what should be done, not how. Classes implement interfaces to provide behavior. This promotes decoupling and allows multiple implementations to be swapped easily.

Que 49. What’s the purpose of the instanceof operator in Java OOP?

Used to check the actual type of an object at runtime, especially in polymorphic contexts.

if (obj instanceof Student) {
   ((Student) obj).study();
}

Helps in safe casting and executing subclass-specific logic.

Que 50. How does encapsulation help in securing Java applications?

By marking variables private and exposing them via getters/setters, developers control access to internal data, prevent unintended modifications, and add validation logic where needed.

Que 51. What is tight coupling vs. loose coupling in Java?

  • Tight Coupling: Classes are dependent on specific implementations.
  • Loose Coupling: Classes depend on abstractions (e.g., interfaces), improving flexibility and testability.

Example using loose coupling:

interface Payment {
    void pay();
}
class CreditCard implements Payment {
    public void pay() {
        System.out.println("Paid with credit card.");
    }
}

Java OOPs Interview Questions PDF

If you want to review these Java OOPs interview questions offline or share them with others, you can download the PDF version of this guide. It includes all the questions and answers shared above.

We have also published other technical interview questions guides that you can explore on this platform