OOPs Interview Questions for Freshers 2027 (Java, C++ & Python Examples)

OOPs Interview Questions for Freshers 2027 (Java, C++ & Python Examples)

Mastering oops interview questions for freshers is non-negotiable if you are targeting software engineering roles in 2027. Whether you are sitting for campus placements at TCS, Infosys, Capgemini, or Wipro, or interviewing at product startups, Object-Oriented Programming (OOPs) forms the backbone of Round 1 coding evaluations and technical face-to-face interviews. Interviewers do not just ask textbook definitions—they test whether you can translate encapsulation, inheritance, polymorphism, and SOLID principles into clean Java, C++, or Python code.

If you are preparing for service-based or specialist programmer tracks, pair these OOPs concepts with hands-on problem solving from our Infosys Round 2 top 80 coding questions for SP and DSE practice and test your readiness using the Infosys System Engineer Mock Test 1. Below are 32 high-frequency OOPs interview questions for freshers organized from fundamentals to advanced design concepts, complete with concise code snippets and comparison tables.

OOPs Fundamentals & The 4 Pillars (Q1–Q10)

Q1. What is Object-Oriented Programming (OOPs), and how does it differ from Procedural Programming?

Object-Oriented Programming organizes software around objects that bundle state (attributes/fields) and behavior (methods) together, rather than separating data and functions. Procedural programming (like C) follows a top-down sequence of routines acting on global or passed data, making large codebases harder to maintain. OOPs improves modularity, reusability, and security through encapsulation, inheritance, abstraction, and polymorphism.

Q2. What is the difference between a Class and an Object?

A Class is a logical blueprint or user-defined data type that defines properties and methods without allocating runtime memory for instance fields. An Object is a concrete runtime instance created from that blueprint, occupying memory on the heap (in Java/Python) or stack/heap (in C++).

// Java Example
class Candidate {
    String name;
    void introduce() { System.out.println("Hi, I am " + name); }
}
Candidate c1 = new Candidate(); // Object instance

Q3. What are the 4 pillars of OOPs?

The four foundational pillars of OOPs are Encapsulation (bundling data with methods and restricting direct access), Abstraction (exposing only essential behavior while hiding implementation complexity), Inheritance (reusing and extending behavior from a parent class), and Polymorphism (allowing one interface or method name to take multiple forms).

Q4. Explain Encapsulation with a real-world coding example.

Encapsulation hides internal object state using access modifiers (such as private) and exposes controlled access via public getters and setters with validation logic. This prevents invalid external mutations.

# Python Example
class BankAccount:
    def __init__(self, balance):
        self.__balance = balance  # private attribute

    def deposit(self, amount):
        if amount > 0:
            self.__balance += amount

    def get_balance(self):
        return self.__balance

Q5. What is Abstraction, and how is it different from Encapsulation?

Abstraction focuses on what an object does by hiding complex internal implementation behind a clean interface (e.g., calling list.sort() without knowing whether Timsort runs underneath). Encapsulation focuses on how data is protected by wrapping fields and methods inside a class and controlling visibility. In short, abstraction solves design-level complexity, while encapsulation enforces data hiding.

Q6. What is Inheritance, and what are its main types?

Inheritance enables a child (derived/subclass) to acquire properties and methods of a parent (base/superclass), promoting an IS-A relationship and code reuse. The main types are: Single (A → B), Multilevel (A → B → C), Hierarchical (A → B and A → C), Multiple (A, B → C — supported directly in C++ and Python, and via interfaces in Java), and Hybrid (a combination of two or more types).

Q7. What is the Diamond Problem in Multiple Inheritance, and how do Java, C++, and Python solve it?

The Diamond Problem occurs when class D inherits from classes B and C, both of which inherit from class A. If A defines a method overridden by both B and C, D faces ambiguity over which version to inherit.

  • C++: Uses virtual inheritance (class B : virtual public A) so only one shared copy of A exists, plus explicit scope resolution (B::show()).
  • Java: Disallows multiple class inheritance; interfaces with conflicting default methods force the implementing class to explicitly override and resolve the call (B.super.show()).
  • Python: Resolves method lookup deterministically using MRO (Method Resolution Order) via the C3 linearization algorithm (inspectable via D.mro()).

Q8. What is Polymorphism, and what are its two types?

Polymorphism means “many forms”—the ability of a single method, operator, or object reference to behave differently depending on context. Compile-time (Static) Polymorphism is resolved during compilation via method overloading or operator overloading (C++/Python). Runtime (Dynamic) Polymorphism is resolved at runtime via method overriding using dynamic method dispatch / virtual tables.

Q9. What is Runtime Polymorphism (Dynamic Method Dispatch) in Java and C++?

When a parent class reference points to a child class object and invokes an overridden method, the JVM or C++ vtable calls the child’s implementation at runtime rather than the reference type’s implementation.

// C++ Example
class Shape {
public:
    virtual void draw() { cout << "Drawing Shape"; }
};
class Circle : public Shape {
public:
    void draw() override { cout << "Drawing Circle"; }
};
Shape* s = new Circle();
s->draw(); // Outputs: Drawing Circle

Q10. What are Access Specifiers (public, private, protected, default)?

Access specifiers control symbol visibility. private restricts access to the declaring class; protected allows access within the same package (Java) and subclasses; public grants universal access. Java also has package-private (default) visibility when no keyword is specified, whereas C++ defaults to private in classes and public in structs.

Method Overloading vs Method Overriding (Q11–Q15)

Q11. What is the difference between Method Overloading and Method Overriding?

This is one of the most frequently asked oops interview questions for freshers. Overloading happens within the same class with different parameter lists, while overriding happens across parent-child classes with an identical signature.

Feature Method Overloading Method Overriding
Binding Time Compile-time (Static Polymorphism) Runtime (Dynamic Polymorphism)
Scope Same class (or subclass adding new signatures) Parent and Child classes (Inheritance required)
Parameters Must differ in count, type, or order Must be identical
Return Type Can differ (cannot overload by return type alone) Must be same or covariant subtype
Access Modifier Any modifier allowed Cannot be more restrictive than parent method
static / private / final Can be overloaded Cannot be overridden (static methods are hidden)

Q12. Can we overload the main() method in Java?

Yes. You can define multiple overloaded main methods with different parameter lists in a Java class. However, the JVM always starts program execution strictly from public static void main(String[] args).

Q13. Can we override static or private methods in Java?

No. private methods are not visible to subclasses, so defining a same-named method in a child class creates a completely separate method. static methods belong to the class rather than an object instance; redefining one in a subclass causes method hiding, meaning the call resolves based on the reference type, not the runtime object.

Q14. Can you overload a method solely by changing its return type?

No. In both Java and C++, changing only the return type while keeping the method name and parameter list identical causes a compile-time error because the compiler cannot determine which version to invoke when the caller ignores the return value.

Q15. Does Python support Method Overloading directly?

Python does not support traditional compile-time overloading by signature—if you define two methods with the same name in a class, the second overwrites the first. Instead, Python achieves overloading behavior using default arguments (def add(a, b=0, c=0)), variable-length arguments (*args, **kwargs), or @functools.singledispatch.

Abstract Class vs Interface (Q16–Q20)

Q16. What is the difference between an Abstract Class and an Interface?

Feature Abstract Class Interface (Java 8+ / C# / ABC in Python)
Purpose Partial abstraction + shared base state/code Full contract / capability specification
Methods Both abstract and concrete methods Abstract methods + default/static/private helpers
Variables Instance fields (mutable, static, final) public static final constants only (in Java)
Constructors Can have constructors (called via super()) Cannot have constructors
Inheritance A class can extend only one abstract class A class can implement multiple interfaces

Q17. When should you choose an Abstract Class over an Interface?

Choose an Abstract Class when closely related classes share common state (instance fields), constructor initialization, or protected helper logic (e.g., Vehicle → Car, Bike). Choose an Interface when unrelated classes need to implement a shared capability or contract (e.g., Flyable implemented by both Drone and Bird) or when you need multiple inheritance of type.

Q18. Can an Abstract Class have a constructor if it cannot be instantiated directly?

Yes. You cannot execute new AbstractClass() directly, but its constructor is invoked via super() when a concrete subclass object is created, ensuring the base class’s fields and invariants are properly initialized.

Q19. Can an Abstract Class exist without any abstract methods?

Yes. Marking a class abstract even when all its methods are concrete prevents direct instantiation and signals that the class is intended strictly as a base class for inheritance (common in adapter classes).

Q20. How does C++ represent Interfaces?

C++ does not have an interface keyword. Developers create an interface by writing an abstract class containing only pure virtual functions (virtual void connect() = 0;) and a virtual destructor, with no non-static data members.

Constructors, Keywords & Memory Concepts (Q21–Q26)

Q21. What are Default, Parameterized, and Copy Constructors?

  • Default Constructor: Takes no arguments; supplied automatically by Java/C++ compilers only if no other constructor is declared.
  • Parameterized Constructor: Accepts arguments to initialize instance variables with caller-provided values.
  • Copy Constructor: Creates a new object as a copy of an existing object (built-in / customizable in C++ as ClassName(const ClassName& obj); implemented manually in Java as a constructor accepting the same class type).

Q22. What is Constructor Chaining?

Constructor chaining is the process of calling one constructor from another within the same class using this(...) or from a parent class using super(...) (Java) or base initializer lists (C++). It avoids duplicate initialization code and guarantees parent state is set up first.

Q23. Differentiate between this and super keywords.

this refers to the current class instance—used to resolve field shadowing (this.name = name), invoke overloaded constructors (this()), or pass the current object as an argument. super refers to the immediate parent class—used to invoke parent constructors (super()) or access overridden parent methods and hidden fields.

Q24. What is the difference between static and final (or const in C++)?

static means a member belongs to the class itself rather than individual objects, so all instances share a single copy in memory. final (in Java) restricts modification: a final variable cannot be reassigned, a final method cannot be overridden, and a final class (like String) cannot be inherited. In C++, const enforces immutability and final prevents overriding/inheritance.

Q25. Explain Shallow Copy vs Deep Copy with an example.

A Shallow Copy duplicates an object’s top-level primitive fields and copies references (pointers) for nested objects. Modifying a nested mutable field in the copy also mutates the original. A Deep Copy recursively clones all nested objects, ensuring complete memory isolation between the original and the copy.

# Python Shallow vs Deep Copy
import copy
original = [[1, 2], [3, 4]]
shallow = copy.copy(original)
deep = copy.deepcopy(original)
shallow[0][0] = 99  # Mutates original[0][0] too!
deep[1][0] = 77     # Leaves original untouched

Q26. Why are Virtual Destructors important in C++, and how does Garbage Collection differ in Java/Python?

In C++, if you delete a derived class object through a base class pointer (Base* ptr = new Derived(); delete ptr;) without a virtual destructor in Base, only ~Base() runs, causing resource leaks in Derived. Making ~Base() virtual ensures ~Derived() runs first. In contrast, Java and Python use automatic Garbage Collection (tracing/mark-and-sweep in JVM; reference counting + cycle detector in CPython) to reclaim unreachable heap objects.

Relationships, SOLID Principles & Design Questions (Q27–Q32)

Q27. Differentiate between Association, Aggregation, and Composition.

All three model HAS-A relationships, unlike Inheritance (IS-A):

  • Association: General relationship where independent objects interact (e.g., Student and Teacher).
  • Aggregation (Weak HAS-A): Whole-part relationship where the part can outlive the whole (e.g., Department has Professors; deleting the department does not destroy the professors).
  • Composition (Strong HAS-A): Whole-part relationship where the part’s lifecycle depends strictly on the whole (e.g., House has Rooms; destroying the house destroys its rooms).

Q28. Why should you prefer Composition over Inheritance?

Deep inheritance hierarchies create tight coupling—changes in a parent class can unexpectedly break subclasses (the fragile base class problem). Composition delegates behavior to injected helper objects, keeping classes loosely coupled, easier to unit test, and flexible at runtime.

Q29. What are the SOLID Principles?

Interviewers frequently ask freshers to name and explain SOLID:

  • S — Single Responsibility Principle (SRP): A class should have only one reason to change.
  • O — Open/Closed Principle (OCP): Software entities should be open for extension but closed for modification.
  • L — Liskov Substitution Principle (LSP): Subclasses must be cleanly substitutable for their base classes without breaking correctness.
  • I — Interface Segregation Principle (ISP): Prefer smaller, role-specific interfaces over fat general-purpose interfaces.
  • D — Dependency Inversion Principle (DIP): High-level modules should depend on abstractions, not concrete implementations.

Q30. What is Cohesion vs Coupling?

Cohesion measures how closely related the responsibilities inside a single class or module are (aim for High Cohesion). Coupling measures how strongly one class depends on the internal details of another (aim for Low Coupling).

Q31. Can a class be declared private or static in Java?

A top-level Java class cannot be private or static (it can only be public or package-private). However, an inner (nested) class can be declared both private and static.

Q32. Scenario Question: How would you design an OOPs class hierarchy for an E-Commerce Payment System?

Create a PaymentMethod interface (or abstract class) with a pay(double amount) contract. Implement concrete classes like UpiPayment, CardPayment, and NetBankingPayment. Use a CheckoutService that depends on the PaymentMethod abstraction (DIP + OCP + Runtime Polymorphism), so adding a new wallet option tomorrow requires zero edits to CheckoutService.

Frequently Asked Questions (FAQs)

1. Which programming language is best for answering OOPs interview questions as a fresher?

Java and C++ are the clearest languages for demonstrating strict OOPs rules such as interfaces, access modifiers, abstract classes, and compile-time vs runtime polymorphism. Python is equally acceptable if you clearly explain duck typing, abc.ABC abstract base classes, name mangling, and MRO.

2. Are SOLID principles expected from 2027 freshers?

Yes, especially in product companies, Infosys SP/DSE, and startup technical rounds. Knowing at least SRP, OCP, and DIP with one small example sets you apart from candidates who only memorize the 4 pillars.

3. How many OOPs questions are typically asked in a fresher technical round?

Expect 3 to 6 targeted OOPs questions alongside DBMS and coding problems. Interviewers often start with “Explain polymorphism with your project” and follow up with overloading vs overriding or abstract class vs interface.

4. What is the most common mistake freshers make in OOPs interviews?

Confusing Abstraction with Encapsulation, claiming constructors can be inherited or overridden, and forgetting that Java does not support multiple inheritance of classes due to the Diamond Problem.

About the author

Watch the video guides on YouTube, get job alerts on the WhatsApp channel, or read how we check our information.