Java

Java OOP Interview Questions

12 questions with answers · Java Interview Guide

Inheritance, polymorphism, encapsulation, abstraction, and SOLID principles. The first topic freshers face in interviews.

bar_chartQuick stats
Total questions12
High frequency3
With code examples3
1

What is OOP

OOP encapsulates data and behavior using inheritance, polymorphism, encapsulation, and abstraction to build maintainable, reusable code.

java
class Animal {
  void sound() {
  }
}
class Dog extends Animal {
  @Override void sound() {
    System.out.println("Bark");
  }
}
Dog dog = new Dog();
dog.sound();
2

What are the principles of OOP

Encapsulation (data hiding), Abstraction (hide complexity), Inheritance (code reuse), Polymorphism (runtime behavior determination).

java
class Animal {
  void sound() {
  }
}
class Dog extends Animal {
  void sound() {
    System.out.println("Bark");
  }
}
interface Pet {
  void play();
}
class Cat implements Pet {
  public void play() {
    System.out.println("Play");
  }
}
3

What is polymorphism

Polymorphism is the ability of objects to take multiple forms,method overloading (compile-time) and method overriding (runtime) enable subclasses to override parent behavior.

java
class Animal {
  void sound() {
  }
}
class Dog extends Animal {
  void sound() {
    System.out.println("Woof");
  }
}
Animal a = new Dog();
a.sound();
4

What are the advantages and disadvantages of the OOP compared to procedural and functional programming

OOP provides modularity, reusability, and encapsulation; procedural is simpler but lacks abstraction; functional emphasizes immutability and composition,OOP balances power and complexity.

5

What are the advantages and disadvantages of the OOP compared to procedural and functional programming

OOP provides modularity, reusability, and encapsulation; procedural is simpler but less maintainable; functional enables parallelization and immutability but has steeper learning curve.

6

What is the "Inheritance"

Inheritance allows a class to acquire properties and methods from a parent class, enabling code reuse and establishing an 'is-a' relationship in OOP hierarchy.

7

How can you describe an abstraction

Abstraction hides implementation complexity and exposes only essential features through interfaces or abstract classes, simplifying usage for clients.

8

What is a "messaging"

Messaging is communication between objects where one object sends a message (method call) to another to request an action.

9

Tell me about the interface

An interface is a contract defining abstract methods that implementing classes must provide; enables polymorphism and multiple inheritance of type.

10

What implies in terms of the principles of OOP expression "is" and "has"

'is-a' implies inheritance (class extends parent), while 'has-a' implies composition (object contains another object as a member).

11

What is the difference between composition and aggregation

Composition is strong ownership where the parent controls the child's lifecycle; aggregation is weak association where objects are independent.

12

What is the difference between static and dynamic binding in Java

Static binding (method overloading) resolved at compile-time based on reference type; dynamic binding (method overriding) resolved at runtime based on actual object type.

Ready to build something real?

Learn ML engineering by building tokenizers, transformers, vector databases, RAG systems, and more from scratch.

Start buildingarrow_forward

More Java topics