DSA Tracker

DSA Tracker

Object-Oriented Programming interview practice

The 40 OOP questions, ranked by how many of the surveyed prep sources list each one.

Object-Oriented Programming Interview Questions (All 40 Reference)

Printable cheat sheet →
#1 (oop-001)•medium•Asked in 11 surveyed sources

What is polymorphism, and what are its types?

Interview one-liner: Polymorphism lets one interface or method call behave differently depending on the object or arguments, mainly through overloading at compile time and overriding at run time.

#2 (oop-002)•easy•Asked in 11 surveyed sources

What is object-oriented programming (OOP)?

Interview one-liner: Object-oriented programming organises a program as objects that combine data and the operations on that data, built from classes.

#3 (oop-003)•easy•Asked in 11 surveyed sources

Which statement about a Java constructor is correct?

Interview one-liner: A constructor is a special method, named after its class with no return type, that the runtime calls automatically to initialise a new object.

#4 (oop-004)•easy•Asked in 10 surveyed sources

What is an object?

Interview one-liner: An object is a runtime instance of a class that holds its own field values and responds to the methods its class defines.

#5 (oop-005)•easy•Asked in 10 surveyed sources

What is inheritance, and what is its purpose?

Interview one-liner: Inheritance lets a new class reuse and extend the members of an existing class, modelling an is-a relationship between them.

#6 (oop-006)•easy•Asked in 9 surveyed sources

Which design best shows encapsulation in Java?

Interview one-liner: Encapsulation keeps an object's data private and changes it only through methods that can enforce the class's own rules.

#7 (oop-007)•medium•Asked in 9 surveyed sources

Which statement best describes abstraction?

Interview one-liner: Abstraction exposes only the essential behaviour of an object and hides the implementation details behind it.

#8 (oop-008)•easy•Asked in 9 surveyed sources

What is a class?

Interview one-liner: A class is a user-defined blueprint that declares the fields and methods every object of that type will have.

#9 (oop-009)•easy•Asked in 9 surveyed sources

What are the main features, or four pillars, of OOP?

Interview one-liner: The four pillars of OOP are encapsulation, abstraction, inheritance and polymorphism, which together structure code around objects and their behaviour.

#10 (oop-010)•medium•Asked in 9 surveyed sources

What is the difference between method overloading and method overriding?

Interview one-liner: Overloading gives one class several methods with the same name and different parameters, while overriding replaces an inherited method's behaviour in a subclass.

#11 (oop-011)•medium•Asked in 9 surveyed sources

Which statement about destructors is correct?

Interview one-liner: A C++ destructor, written as a tilde and the class name, runs automatically when an object's lifetime ends to release what it holds.

#12 (oop-012)•easy•Asked in 8 surveyed sources

In Java, which access modifier allows a member to be used only inside its own class?

Interview one-liner: The private modifier restricts a Java member to the class that declares it, which is the strictest of the four access levels.

#13 (oop-013)•easy•Asked in 8 surveyed sources

In Java, what is the name of the no-argument constructor that the compiler supplies when a class declares no constructor?

Interview one-liner: The default constructor is the no-argument constructor that Java supplies only when a class declares no constructor of its own.

#14 (oop-014)•medium•Asked in 7 surveyed sources

In C++, how do a struct and a class differ by default?

Interview one-liner: In C++, a struct and a class are nearly identical, and the one default difference is that struct members are public while class members are private.

#15 (oop-015)•easy•Asked in 7 surveyed sources

Which inheritance type has one base class with several derived classes that each extend it directly?

Interview one-liner: Hierarchical inheritance is the form where one base class has several derived classes that each extend it directly.

#16 (oop-016)•medium•Asked in 7 surveyed sources

How is an abstract class different from an interface?

Interview one-liner: An abstract class can share state and code with its subclasses, while an interface defines a contract that any unrelated class can implement.

#17 (oop-017)•hard•Asked in 7 surveyed sources

In C++, which member declaration makes a class abstract?

Interview one-liner: In C++ a class becomes abstract when it has at least one pure virtual function, declared with = 0 after the function.

#18 (oop-018)•easy•Asked in 7 surveyed sources

What are the advantages and disadvantages of OOP?

Interview one-liner: OOP improves reuse, modularity and maintenance, but its extra design structure can add complexity and overhead when a problem is small.

#19 (oop-019)•medium•Asked in 6 surveyed sources

Which statement about a Java interface is correct?

Interview one-liner: A Java class can implement any number of interfaces but extend only one superclass, which is how Java offers multiple types of behaviour.

#20 (oop-020)•medium•Asked in 6 surveyed sources

Which statement about an abstract class in Java is correct?

Interview one-liner: An abstract class in Java cannot be instantiated directly, but it can hold constructors, fields and concrete methods for its subclasses to use.

#21 (oop-021)•easy•Asked in 6 surveyed sources

Compared with procedural programming, what is the main unit that OOP organises a program around?

Interview one-liner: Unlike procedural code that separates data from functions, OOP organises a program around objects that bundle their data with their operations.

#22 (oop-022)•medium•Asked in 6 surveyed sources

Which change makes a method in a Java subclass a valid override of a superclass method?

Interview one-liner: A Java subclass method overrides its parent's method only when the name and parameter list match and access is not narrowed.

#23 (oop-023)•easy•Asked in 5 surveyed sources

Why do we need OOP?

Interview one-liner: OOP helps organise large programs into reusable, self-contained units whose internal details can change without breaking the rest of the code.

#24 (oop-024)•easy•Asked in 5 surveyed sources

Name some major object-oriented programming languages.

Interview one-liner: Common object-oriented languages include Java, C++, C#, Python and Ruby, with Smalltalk as an early pioneer of the style.

#25 (oop-025)•medium•Asked in 5 surveyed sources

What are the limitations of inheritance?

Interview one-liner: Inheritance couples a subclass tightly to its parent, can break encapsulation, and in Java allows only one superclass, so composition is sometimes better.

#26 (oop-026)•hard•Asked in 5 surveyed sources

In Java, what does a class declaration itself take up in memory at run time?

Interview one-liner: A Java class declaration stores shared type information once, while each object gets memory only for its own instance fields.

#27 (oop-027)•medium•Asked in 5 surveyed sources

In Java, can a method be called without creating an object of its class?

Interview one-liner: In Java a static method can be called through the class name with no object, but an instance method needs an object to run against.

#28 (oop-028)•medium•Asked in 5 surveyed sources

What is the difference between abstraction and encapsulation?

Interview one-liner: Abstraction hides complexity by exposing only essential behaviour, while encapsulation protects an object's data by restricting direct access to it.

#29 (oop-029)•hard•Asked in 5 surveyed sources

Which relationship is a whole-part link in which the part can exist without the whole and can be shared between wholes?

Interview one-liner: Aggregation is a whole-part link where the part can exist independently of the whole, unlike composition where the part's lifetime depends on it.

#30 (oop-030)•hard•Asked in 5 surveyed sources

In Java, which decision is made at run time through dynamic dispatch?

Interview one-liner: In Java, dynamic dispatch picks the overriding method at run time based on the object's actual class, while overloads are fixed at compile time.

#31 (oop-031)•easy•Asked in 5 surveyed sources

Which pair of methods declared in one Java class is a valid overload?

Interview one-liner: A valid Java overload needs the same name in one class with a different parameter list, meaning different types or number of parameters.

#32 (oop-032)•hard•Asked in 5 surveyed sources

Why is multiple inheritance of classes not supported in Java, and what is the diamond problem?

Interview one-liner: The diamond problem is ambiguity when a class inherits the same base through two paths, so Java allows one superclass and uses interfaces instead.

#33 (oop-033)•medium•Asked in 4 surveyed sources

In Java, what does a copy constructor do?

Interview one-liner: A copy constructor in Java is a constructor you write that builds a new object from an existing object of the same class.

#34 (oop-034)•easy•Asked in 4 surveyed sources

What is a superclass and a subclass?

Interview one-liner: A superclass is the class being extended, and a subclass is the class that extends it, inheriting its accessible members and adding its own.

#35 (oop-035)•medium•Asked in 4 surveyed sources

In Java exception handling, which block runs whether or not an exception was thrown?

Interview one-liner: In Java the finally block runs whether or not an exception was thrown, so it is the place for cleanup such as closing resources.

#36 (oop-036)•easy•Asked in 4 surveyed sources

Which statement distinguishes a class from an object?

Interview one-liner: A class is the blueprint that declares fields and methods, and an object is an instance created from that blueprint with its own values.

#37 (oop-037)•medium•Asked in 4 surveyed sources

In a Java subclass constructor, which use of super is correct?

Interview one-liner: In Java, super(...) calls a superclass constructor, and before JDK 25 it had to be the first statement in the subclass constructor.

#38 (oop-038)•easy•Asked in 4 surveyed sources

What does the final keyword do for a variable, a method and a class?

Interview one-liner: The final keyword fixes a variable to one assignment, stops a method being overridden, and stops a class being extended.

#39 (oop-039)•medium•Asked in 3 surveyed sources

Which statement about garbage collection in Java is correct?

Interview one-liner: Java's garbage collector automatically reclaims objects that can no longer be reached, at a time the runtime chooses.

#40 (oop-040)•easy•Asked in 3 surveyed sources

In a Java constructor, what does this.name = name; do when name is a parameter?

Interview one-liner: In a Java constructor, this.name = name; copies the parameter into the object's field, because this points to the current object.

More interview rounds