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.
What is OOP
OOP encapsulates data and behavior using inheritance, polymorphism, encapsulation, and abstraction to build maintainable, reusable code.
class Animal {
void sound() {
}
}
class Dog extends Animal {
@Override void sound() {
System.out.println("Bark");
}
}
Dog dog = new Dog();
dog.sound();What are the principles of OOP
Encapsulation (data hiding), Abstraction (hide complexity), Inheritance (code reuse), Polymorphism (runtime behavior determination).
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");
}
}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.
class Animal {
void sound() {
}
}
class Dog extends Animal {
void sound() {
System.out.println("Woof");
}
}
Animal a = new Dog();
a.sound();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.
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.
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.
How can you describe an abstraction
Abstraction hides implementation complexity and exposes only essential features through interfaces or abstract classes, simplifying usage for clients.
What is a "messaging"
Messaging is communication between objects where one object sends a message (method call) to another to request an action.
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.
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).
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.
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.
Knowing the answers is half the battle
The other half is explaining them clearly under pressure.
Try a free mock interviewarrow_forward