Blog/OOPs Interview Questions for Freshers: 25 Questions With Code Examples

OOPs Interview Questions for Freshers: 25 Questions With Code Examples

25 fresher-level OOPs interview questions with complete answers, Java and Python code, a topic-weighting table and a 7-day plan.

Last updated: 13 October 2026 · By the Asuraa Team

Quick answer: The OOPs interview questions freshers face most cover the four pillars (encapsulation, abstraction, inheritance, polymorphism), class vs object, overloading vs overriding, abstract class vs interface, the diamond problem and constructors. Know the language nuance: Oracle's Java tutorial explains that Java classes have single inheritance but support multiple inheritance of type through interfaces. Answer each question with a definition, a reason and a short code example.

Key takeaways

  • Fresher OOPs interviews focus on the four pillars, inheritance and the diamond problem, overloading vs overriding, abstract classes vs interfaces and object lifecycle.
  • Oracle's Java tutorial explains that a Java class can extend only one class but can implement many interfaces, giving multiple inheritance of type.
  • In Java, a static method in a subclass hides the parent's static method rather than overriding it, so the reference type decides which version runs.
  • Python's official tutorial states that all Python methods are effectively virtual and that double-underscore name mangling exists to avoid accidental name clashes, not to enforce privacy.
  • An abstract class can have a constructor that runs when a concrete subclass is created, even though the abstract class itself cannot be instantiated.

OOPs interviews for freshers test whether you understand the four pillars (encapsulation, abstraction, inheritance, polymorphism) well enough to apply them, not just recite them. The 25 questions below are grouped by area, each with a complete answer and short code in Java or Python, the two languages most freshers use. Most answers are language-neutral; where Java and Python differ, the answer says so and links the official documentation.

Which OOPs topics carry the most weight in fresher interviews?

Polymorphism and inheritance carry the most weight, because they lead to follow-up questions about overloading, overriding and abstract classes.

AreaTypical questionsWhat interviewers check
BasicsClass vs object, four pillars, OOP vs proceduralClear definitions with real examples
Encapsulation and abstractionDifference between them, access modifiersWhether you can separate the two ideas
InheritanceTypes, diamond problem, compositionDesign judgement, not only syntax
PolymorphismOverloading vs overriding, dynamic dispatchCompile-time vs runtime reasoning
Abstract classes and interfacesWhen to use whichChoosing the right tool
Object lifecycle and designConstructors, static, SOLIDReadiness to write maintainable code

The interview questions by subject guide lists question banks for DBMS, OS, networks and DSA, which usually appear in the same technical round.

What basic OOPs questions are asked?

1. What is object-oriented programming?

OOP is a way of structuring a program around objects that bundle data (state) with the methods that operate on it (behaviour). Oracle's OOP concepts lesson describes an object as a bundle of related state and behaviour, often modelling something from the real world. The goal is code that is modular, reusable and easier to change.

2. What is the difference between a class and an object?

A class is a blueprint that defines fields and methods; an object is a concrete instance created from it with its own field values. Car is a class, while your car with registration KA-01-AB-1234 is an object. A class takes no memory for instance data until you create objects.

class Car { String number; void start() { System.out.println(number + " started"); } }
Car mine = new Car(); mine.number = "KA01AB1234"; mine.start();

3. What are the four pillars of OOP?

Encapsulation hides an object's data behind methods. Abstraction exposes only what a user of the object needs. Inheritance lets a class reuse and extend another class. Polymorphism lets one interface take many forms, so the same call behaves differently depending on the object. Always add a one-line example for each.

4. How is OOP different from procedural programming?

Procedural programming organises code as functions that act on separate data, as in C. OOP keeps data and behaviour together in objects and controls access to the data. OOP scales better for large systems with many interacting entities, while procedural code is often simpler for small scripts and performance-critical routines.

What encapsulation and abstraction questions come up?

5. What is encapsulation? Give an example.

Encapsulation means keeping fields private and allowing changes only through methods that enforce rules. A bank account should not let anyone set a negative balance directly; a withdraw method checks the amount first. In Python there is no truly private field: a leading underscore is a convention, and the Python classes tutorial explains that names like __balance are name-mangled to _ClassName__balance mainly to avoid clashes with subclasses.

class Account {
  private double balance;
  public void withdraw(double amt) {
    if (amt <= 0 || amt > balance) throw new IllegalArgumentException("Invalid amount");
    balance -= amt;
  }
  public double getBalance() { return balance; }
}

6. What is the difference between abstraction and encapsulation?

Abstraction is about design: showing only the essential operations and hiding complexity, like a car's steering wheel and pedals hiding the engine. Encapsulation is about implementation: protecting an object's internal data with access control. Abstraction answers "what should users see?"; encapsulation answers "how do I protect the internals?". Abstract classes and interfaces implement abstraction; private fields with methods implement encapsulation.

7. What are access modifiers?

Access modifiers control visibility. In Java, private is class-only, default (no keyword) is package-only, protected adds subclasses, and public is visible everywhere. C++ has private, protected and public, while Python relies on naming conventions. Keep fields as restrictive as possible and widen only when needed.

What inheritance questions should freshers prepare?

8. What is inheritance and what are its types?

Inheritance lets a subclass acquire fields and methods of a superclass and add or change behaviour, modelling an "is-a" relationship: a SavingsAccount is an Account. Common types are single, multilevel (A to B to C), hierarchical (several classes from one parent), multiple (one class from several parents) and hybrid. Java classes support single, multilevel and hierarchical; C++ and Python also support multiple inheritance.

9. What is the diamond problem and how do languages handle it?

The diamond problem arises when class D inherits from B and C, which both inherit from A, so it is unclear which version of A's members D gets. Java avoids it for classes by allowing only one superclass and permitting multiple interfaces; Oracle's tutorial on multiple inheritance explains that if two interfaces provide the same default method, the class must override it. Python allows multiple inheritance and resolves lookups with a method resolution order that calls each parent once, visible through D.__mro__. C++ uses virtual inheritance.

class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass
print(D.__mro__)  # D, B, C, A, object

10. What is the difference between inheritance and composition?

Inheritance models "is-a"; composition models "has-a", where a class holds references to other objects: a Car has an Engine. Composition is usually more flexible because you can swap parts at runtime and avoid fragile deep hierarchies, which is why "favour composition over inheritance" is common advice. Aggregation is a weaker "has-a" where the part can exist independently, like a department and its professors.

11. What does the super keyword do?

super refers to the parent class. In Java, super(...) calls the parent constructor (it must be the first statement), and super.method() calls the parent's version of an overridden method. Python's super().__init__() does the same and follows the method resolution order in multiple inheritance.

What polymorphism questions are asked?

12. What is the difference between compile-time and runtime polymorphism?

Compile-time (static) polymorphism is method overloading: the compiler chooses which method to call from the argument types. Runtime (dynamic) polymorphism is method overriding: the method that runs depends on the actual object type at runtime, even when the reference has the parent type. Runtime polymorphism is what lets you write code against a parent type and plug in new subclasses later.

Shape s = new Circle(2);
s.area(); // Circle's area() runs at runtime

13. What is the difference between overloading and overriding?

Overloading is the same method name with different parameter lists in the same class; return type alone cannot distinguish overloads. Overriding is a subclass redefining an inherited instance method with the same signature. Per Oracle's overriding tutorial, an overriding method can widen access but not narrow it and may return a subtype of the original return type. The @Override annotation makes the compiler check that you really are overriding.

14. What are virtual functions?

A virtual function is one whose call is resolved at runtime based on the object's real type. In C++ you mark it with the virtual keyword; in Java every non-static, non-private, non-final instance method behaves this way. The Python classes tutorial notes that all Python methods are effectively virtual, so a base-class method calling self.name() will run a subclass override.

15. Can static methods be overridden?

No. In Java, a static method with the same signature in a subclass hides the parent's method rather than overriding it, so the version called depends on the reference type, not the object. Oracle's overriding tutorial shows that Animal.testClassMethod() runs the parent's static method while an instance call on the same object runs the subclass override.

16. Can constructors be overloaded or overridden?

Constructors can be overloaded: a class can have several constructors with different parameters. They cannot be overridden because they are not inherited; each class defines its own. A subclass constructor calls a parent constructor with super(...), implicitly calling the no-argument one if you do not.

What abstract class and interface questions come up?

17. What is the difference between an abstract class and an interface?

An abstract class can hold state (instance fields), constructors and both abstract and concrete methods, and a class can extend only one. An interface defines a contract; in Java its fields are always public static final, and a class can implement many interfaces. Oracle's abstract classes page recommends an abstract class when closely related classes share code and an interface when unrelated classes share a capability, like Comparable.

18. Can an abstract class have a constructor?

Yes. It cannot be instantiated directly, but its constructor runs when a concrete subclass is created, initialising the shared fields. This is a common trick question, and the reasoning is what earns credit.

19. Can you create an object of an abstract class or interface?

No, you cannot instantiate either directly with new. You can, however, declare a variable of that type and assign it any object of a concrete implementing class, which is the basis of runtime polymorphism. In Java you can also create an anonymous class that implements the missing methods on the spot.

What object lifecycle and design questions are asked?

20. What are constructors and destructors?

A constructor initialises a new object and runs automatically when it is created. A destructor runs when an object is destroyed to release resources; C++ has explicit destructors (~ClassName). Java and Python rely on garbage collection, so resources such as files are closed explicitly with try-with-resources in Java or with blocks in Python rather than relying on destructors.

21. What is a shallow copy versus a deep copy of an object?

A shallow copy duplicates the object but shares references to nested objects, so changing a nested list in the copy also changes the original. A deep copy duplicates every nested object too. In C++ this is the reason to write a custom copy constructor; in Python use copy.deepcopy().

22. What is the this keyword?

this (or self in Python) refers to the current object. It distinguishes fields from parameters with the same name, passes the current object to another method, and in Java this(...) calls another constructor of the same class.

23. What is the difference between static and instance members?

Instance members belong to each object, so every object has its own copy of instance fields. Static members belong to the class and are shared by all objects, such as a counter of how many objects were created. Static methods cannot access instance fields directly because there is no current object.

24. What are the SOLID principles?

SOLID is five design principles: Single responsibility (a class has one reason to change), Open/closed (open for extension, closed for modification), Liskov substitution (subclasses must work wherever the parent is expected), Interface segregation (prefer small, focused interfaces) and Dependency inversion (depend on abstractions, not concrete classes). Freshers are rarely grilled on all five, but explaining one with an example from your project impresses.

25. What are coupling and cohesion?

Cohesion is how closely the responsibilities inside one class relate; high cohesion is good. Coupling is how much one class depends on the internals of another; low coupling is good. Well-designed OOP code aims for high cohesion and low coupling, so a change in one class rarely breaks others.

How should you revise OOPs in 7 days before the interview?

Use one language consistently, write every example yourself, and model one small domain, such as a library or a payment system, across the week. The technical interview preparation guide explains how to structure spoken answers.

  1. Day 1: Basics. Class vs object, four pillars, OOP vs procedural. Write one example for each pillar.
  2. Day 2: Encapsulation and abstraction. Build an Account class with validation; explain the difference aloud.
  3. Day 3: Inheritance. Types, the diamond problem, composition vs inheritance. Draw a class diagram.
  4. Day 4: Polymorphism. Overloading vs overriding, static hiding, dynamic dispatch with a Shape hierarchy.
  5. Day 5: Abstract classes and interfaces. Implement a Payment interface with UPI and card classes.
  6. Day 6: Lifecycle and design. Constructors, copies, static members, SOLID, coupling and cohesion.
  7. Day 7: Mock and project. Answer all 25 questions aloud and identify where your own project uses each pillar.

For Java-specific depth, continue with Java interview questions for freshers and how to learn Java for jobs; if you code in C++, see how to learn C++ for placements.

What do most guides on OOPs interview questions get wrong?

Most guides teach the pillars with animal and car analogies but never ask you to apply them to your own code, which is exactly what interviewers do next: "Where did you use polymorphism in your project?" Prepare that answer first. Guides also blur abstraction and encapsulation into one idea, and they state "Java does not support multiple inheritance" without the nuance that it supports multiple inheritance of type through interfaces. Finally, many claim Python has private variables because of double underscores; the official tutorial says name mangling exists to avoid accidental clashes, not to enforce privacy.

Related guides

FAQ

What are the four pillars of OOPs?

The four pillars are encapsulation (hiding data behind methods), abstraction (exposing only essential behaviour), inheritance (reusing and extending a parent class) and polymorphism (one interface, many forms, such as an overridden method behaving differently per object). In an interview, give a short real example for each, ideally from your own project.

What is the difference between overloading and overriding?

Overloading is several methods with the same name but different parameter lists in one class, chosen at compile time. Overriding is a subclass redefining an inherited instance method with the same signature, chosen at runtime by the actual object type. In Java, an override cannot reduce visibility and may return a subtype of the original return type.

Does Java support multiple inheritance?

Not for classes: a Java class can extend only one class, which avoids conflicting inherited state. Java does support multiple inheritance of type, because a class can implement any number of interfaces. If two interfaces provide the same default method, Oracle's tutorial explains that the class must override it and can call a specific one with InterfaceName.super.method().

Which language should I use to answer OOPs questions?

Use the language you know best and that appears on your resume, usually Java, Python or C++. Interviewers care about concepts, but your examples must be correct in that language. Be aware of differences, such as Python allowing multiple inheritance and having no enforced private fields, in case the interviewer asks a follow-up.

How do I answer 'where did you use OOPs in your project'?

Pick one concrete class structure from your project and map it to pillars: for example, a Payment interface with UPI and card implementations shows abstraction and runtime polymorphism, and private fields with validated setters show encapsulation. Mention one design decision you made and why, such as using composition instead of a deep inheritance chain.

Final thoughts

OOPs rounds reward freshers who can point to the pillars in their own code, not those who recite animal analogies. Build one small domain model this week and use it as the example for every answer. If you want feedback on how you explain design decisions, a 1:1 session with an industry mentor on Asuraa mentors can help before the real interview.

Related articles

Share this article

Continue Reading

Data Science Career Paths

Explore different career trajectories in data science and find your perfect fit.

Read article →

Building Your DS Portfolio

Learn how to create projects that impress hiring managers and showcase your skills.

Read article →

Salary Negotiation Guide

Get the compensation you deserve with our proven negotiation strategies.

Review Your Resume →