DSA Tracker

DSA Tracker

← Back to interactive practice

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.

Q1 • oop-001medium • 11 sources

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.

Q2 • oop-002easy • 11 sources

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.

Q3 • oop-003easy • 11 sources

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.

Q4 • oop-004easy • 10 sources

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.

Q5 • oop-005easy • 10 sources

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.

Q6 • oop-006easy • 9 sources

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.

Q7 • oop-007medium • 9 sources

Which statement best describes abstraction?

Answer: Abstraction exposes only the essential behaviour of an object and hides the implementation details behind it.

Q8 • oop-008easy • 9 sources

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.

Q9 • oop-009easy • 9 sources

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.

Q10 • oop-010medium • 9 sources

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.

Q11 • oop-011medium • 9 sources

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.

Q12 • oop-012easy • 8 sources

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.

Q13 • oop-013easy • 8 sources

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.

Q14 • oop-014medium • 7 sources

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.

Q15 • oop-015easy • 7 sources

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.

Q16 • oop-016medium • 7 sources

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.

Q17 • oop-017hard • 7 sources

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.

Q18 • oop-018easy • 7 sources

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.

Q19 • oop-019medium • 6 sources

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.

Q20 • oop-020medium • 6 sources

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.

Q21 • oop-021easy • 6 sources

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.

Q22 • oop-022medium • 6 sources

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.

Q23 • oop-023easy • 5 sources

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.

Q24 • oop-024easy • 5 sources

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.

Q25 • oop-025medium • 5 sources

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.

Q26 • oop-026hard • 5 sources

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.

Q27 • oop-027medium • 5 sources

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.

Q28 • oop-028medium • 5 sources

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.

Q29 • oop-029hard • 5 sources

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.

Q30 • oop-030hard • 5 sources

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.

Q31 • oop-031easy • 5 sources

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.

Q32 • oop-032hard • 5 sources

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.

Q33 • oop-033medium • 4 sources

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.

Q34 • oop-034easy • 4 sources

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.

Q35 • oop-035medium • 4 sources

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.

Q36 • oop-036easy • 4 sources

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.

Q37 • oop-037medium • 4 sources

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.

Q38 • oop-038easy • 4 sources

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.

Q39 • oop-039medium • 3 sources

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.

Q40 • oop-040easy • 3 sources

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.

DSA Tracker • https://dsatracker.tech/core-cs/oop