Skip to content
Interview questions

OOP interview questions

Practise explaining object-oriented design clearly, like you would in a real interview.

Categories

Showing 60 of 60

Mode

01

OOP foundations

What is object-oriented programming, in your own words?

02

OOP foundations

How would you explain the difference between a class and an object?

03

OOP foundations

What roles do fields and methods play inside a class?

04

OOP foundations

What should a constructor be responsible for?

05

OOP foundations

Is a default constructor the same as a no-argument constructor?

06

OOP foundations

Why would you overload or chain constructors?

07

OOP foundations

What is stored when one object variable is assigned to another in Java?

08

Encapsulation and abstraction

What does encapsulation actually protect?

09

Encapsulation and abstraction

Why are getters and setters not automatically good encapsulation?

10

Encapsulation and abstraction

How do abstraction and encapsulation differ?

11

Encapsulation and abstraction

How do you decide whether a member should be public, protected, or private?

12

Encapsulation and abstraction

What is information hiding, and why does it matter?

13

Encapsulation and abstraction

How would you stop an object from entering an invalid state?

14

Inheritance and relationships

What problem is inheritance meant to solve?

15

Inheritance and relationships

How do is-a and has-a relationships influence your design?

16

Inheritance and relationships

Why is composition often preferred over inheritance?

17

Inheritance and relationships

What is the diamond problem in multiple inheritance?

18

Inheritance and relationships

Can you distinguish association, aggregation, and composition?

19

Inheritance and relationships

How does constructor chaining work between a superclass and subclass in modern Java?

20

Inheritance and relationships

What is the fragile base class problem?

21

Polymorphism and binding

What does polymorphism give us in practical code?

22

Polymorphism and binding

What is the difference between method overloading and method overriding?

23

Polymorphism and binding

What do static binding and dynamic binding mean?

24

Polymorphism and binding

A parent reference points to a child object. Which methods and fields are accessible?

25

Polymorphism and binding

Why is upcasting usually safe while downcasting can fail?

26

Polymorphism and binding

Which Java methods cannot participate in normal overriding?

27

Polymorphism and binding

What is a covariant return type?

28

Interfaces and abstract classes

When would you choose an abstract class instead of an interface?

29

Interfaces and abstract classes

Why can a Java class implement multiple interfaces but extend only one class?

30

Interfaces and abstract classes

Why can an abstract class have a constructor if it cannot be instantiated directly?

31

Interfaces and abstract classes

Why were default methods added to Java interfaces?

32

Interfaces and abstract classes

Why do we often depend on an interface rather than a concrete class?

33

Equality, copying, and immutability

What is the difference between object identity and logical equality?

34

Equality, copying, and immutability

Why must equals and hashCode agree in Java?

35

Equality, copying, and immutability

How would you distinguish a shallow copy from a deep copy?

36

Equality, copying, and immutability

Why is assigning an object reference not considered copying the object?

37

Equality, copying, and immutability

How would you design an immutable Java class?

38

Equality, copying, and immutability

What do we gain and lose by making objects immutable?

39

Object context and lifecycle

What is the difference between this and super in Java?

40

Object context and lifecycle

When should a member be static rather than instance-based?

41

Object context and lifecycle

Are static methods polymorphic in Java?

42

Object context and lifecycle

What stages does an object go through during its lifecycle?

43

Object context and lifecycle

Are Java objects always on the heap and local variables always on the stack?

44

SOLID and good design

What do low coupling and high cohesion look like in a design?

45

SOLID and good design

How do you interpret the Single Responsibility Principle?

46

SOLID and good design

What does the Open-Closed Principle mean in practice?

47

SOLID and good design

How can a subclass violate the Liskov Substitution Principle?

48

SOLID and good design

Why is one large interface often worse than several focused interfaces?

49

SOLID and good design

What is Dependency Inversion trying to achieve?

50

SOLID and good design

Can applying SOLID principles ever make a design worse?

51

Design patterns

When is a factory more useful than calling a constructor directly?

52

Design patterns

What problem does the Strategy pattern solve?

53

Design patterns

What trade-off comes with the Observer pattern?

54

Design patterns

Why is Singleton often criticized?

55

Practical design scenarios

How would you design a notification service that supports email, SMS, and push?

56

Practical design scenarios

A checkout must support several payment providers. How would you structure it?

57

Practical design scenarios

A class validates orders, stores them, charges customers, and sends emails. What would you change?

58

Practical design scenarios

Why can making Square inherit from Rectangle cause design problems?

59

Practical design scenarios

How would you model users, roles, and permissions without filling User with conditionals?

60

Practical design scenarios

When would you decide not to use an object-oriented design?