Print or save this cheat sheet to PDF for quick interview revision.
Object-Oriented Programming: Top 40 Fresher Interview Questions
Ranked by how many of the surveyed prep sources list each question. Curated for fast active recall.
What is polymorphism, and what are its types?
Answer: 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.
What is object-oriented programming (OOP)?
Answer: Object-oriented programming organises a program as objects that combine data and the operations on that data, built from classes.
Which statement about a Java constructor is correct?
Answer: A constructor is a special method, named after its class with no return type, that the runtime calls automatically to initialise a new object.
What is an object?
Answer: An object is a runtime instance of a class that holds its own field values and responds to the methods its class defines.
What is inheritance, and what is its purpose?
Answer: Inheritance lets a new class reuse and extend the members of an existing class, modelling an is-a relationship between them.
Which design best shows encapsulation in Java?
Answer: Encapsulation keeps an object's data private and changes it only through methods that can enforce the class's own rules.
Which statement best describes abstraction?
Answer: Abstraction exposes only the essential behaviour of an object and hides the implementation details behind it.
What is a class?
Answer: A class is a user-defined blueprint that declares the fields and methods every object of that type will have.
What are the main features, or four pillars, of OOP?
Answer: The four pillars of OOP are encapsulation, abstraction, inheritance and polymorphism, which together structure code around objects and their behaviour.
What is the difference between method overloading and method overriding?
Answer: Overloading gives one class several methods with the same name and different parameters, while overriding replaces an inherited method's behaviour in a subclass.
Which statement about destructors is correct?
Answer: A C++ destructor, written as a tilde and the class name, runs automatically when an object's lifetime ends to release what it holds.
In Java, which access modifier allows a member to be used only inside its own class?
Answer: The private modifier restricts a Java member to the class that declares it, which is the strictest of the four access levels.
In Java, what is the name of the no-argument constructor that the compiler supplies when a class declares no constructor?
Answer: The default constructor is the no-argument constructor that Java supplies only when a class declares no constructor of its own.
In C++, how do a struct and a class differ by default?
Answer: 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.
Which inheritance type has one base class with several derived classes that each extend it directly?
Answer: Hierarchical inheritance is the form where one base class has several derived classes that each extend it directly.
How is an abstract class different from an interface?
Answer: An abstract class can share state and code with its subclasses, while an interface defines a contract that any unrelated class can implement.
In C++, which member declaration makes a class abstract?
Answer: In C++ a class becomes abstract when it has at least one pure virtual function, declared with = 0 after the function.
What are the advantages and disadvantages of OOP?
Answer: OOP improves reuse, modularity and maintenance, but its extra design structure can add complexity and overhead when a problem is small.
Which statement about a Java interface is correct?
Answer: A Java class can implement any number of interfaces but extend only one superclass, which is how Java offers multiple types of behaviour.
Which statement about an abstract class in Java is correct?
Answer: An abstract class in Java cannot be instantiated directly, but it can hold constructors, fields and concrete methods for its subclasses to use.
Compared with procedural programming, what is the main unit that OOP organises a program around?
Answer: Unlike procedural code that separates data from functions, OOP organises a program around objects that bundle their data with their operations.
Which change makes a method in a Java subclass a valid override of a superclass method?
Answer: A Java subclass method overrides its parent's method only when the name and parameter list match and access is not narrowed.
Why do we need OOP?
Answer: OOP helps organise large programs into reusable, self-contained units whose internal details can change without breaking the rest of the code.
Name some major object-oriented programming languages.
Answer: Common object-oriented languages include Java, C++, C#, Python and Ruby, with Smalltalk as an early pioneer of the style.
What are the limitations of inheritance?
Answer: Inheritance couples a subclass tightly to its parent, can break encapsulation, and in Java allows only one superclass, so composition is sometimes better.
In Java, what does a class declaration itself take up in memory at run time?
Answer: A Java class declaration stores shared type information once, while each object gets memory only for its own instance fields.
In Java, can a method be called without creating an object of its class?
Answer: 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.
What is the difference between abstraction and encapsulation?
Answer: Abstraction hides complexity by exposing only essential behaviour, while encapsulation protects an object's data by restricting direct access to it.
Which relationship is a whole-part link in which the part can exist without the whole and can be shared between wholes?
Answer: 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.
In Java, which decision is made at run time through dynamic dispatch?
Answer: 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.
Which pair of methods declared in one Java class is a valid overload?
Answer: A valid Java overload needs the same name in one class with a different parameter list, meaning different types or number of parameters.
Why is multiple inheritance of classes not supported in Java, and what is the diamond problem?
Answer: The diamond problem is ambiguity when a class inherits the same base through two paths, so Java allows one superclass and uses interfaces instead.
In Java, what does a copy constructor do?
Answer: A copy constructor in Java is a constructor you write that builds a new object from an existing object of the same class.
What is a superclass and a subclass?
Answer: A superclass is the class being extended, and a subclass is the class that extends it, inheriting its accessible members and adding its own.
In Java exception handling, which block runs whether or not an exception was thrown?
Answer: In Java the finally block runs whether or not an exception was thrown, so it is the place for cleanup such as closing resources.
Which statement distinguishes a class from an object?
Answer: A class is the blueprint that declares fields and methods, and an object is an instance created from that blueprint with its own values.
In a Java subclass constructor, which use of super is correct?
Answer: In Java, super(...) calls a superclass constructor, and before JDK 25 it had to be the first statement in the subclass constructor.
What does the final keyword do for a variable, a method and a class?
Answer: The final keyword fixes a variable to one assignment, stops a method being overridden, and stops a class being extended.
Which statement about garbage collection in Java is correct?
Answer: Java's garbage collector automatically reclaims objects that can no longer be reached, at a time the runtime chooses.
In a Java constructor, what does this.name = name; do when name is a parameter?
Answer: In a Java constructor, this.name = name; copies the parameter into the object's field, because this points to the current object.