OOPS interviews test the four pillars (encapsulation, abstraction, inheritance, polymorphism), classes and objects, constructors, overloading versus overriding, abstract class versus interface, composition versus inheritance and the SOLID principles. These 32 answers give the concept first, then how Java and Python each handle it, with tested Python code.
On this page
Core concepts (Q1 to Q8)The four pillars (Q9 to Q16)Abstract classes, interfaces and access (Q17 to Q23)Design and practice (Q24 to Q32)How to prepareFrequently asked questionsFor students and freshers preparing for Java, Python and general software roles, where OOPS is asked in almost every first technical round. Each answer states the concept, then the Java and Python difference, because interviewers often ask for both. The Python demo was run on Python 3.9.6 and the output quoted is what it printed. The Java snippet could not be compiled here (no Java runtime on this machine), so it was proofread, and its output is what the language rules give. Java rules were checked against the Oracle Java tutorial and Java Language Specification, and Python rules against the Python language reference, on 1 December 2026.
Trends India shows interview-question searches for Java, Python, SQL, React and Node peaking from January to March, and those pages rank among the hub's recurring winners. The Search Console export of 26 November 2026 has no direct row for this page, so the "most asked" picks below are our reading, not data. If the pillars are new to you, start with object-oriented programming explained.
Core concepts (Q1 to Q8)
- Q1. What is object-oriented programming? A way of organizing code around objects that bundle data (fields) with the behaviour that works on it (methods). It models real things, hides internals and lets you reuse code through inheritance and composition.
- Q2. What are a class and an object? A class is the blueprint: it declares fields and methods. An object is one instance of that class with its own field values.
Circleis a class,Circle(5)is an object. - Q3. What are the four pillars of OOP? Encapsulation, abstraction, inheritance and polymorphism. Each has its own question below. A common follow-up is to give one real example of each.
- Q4. What is a constructor? Does Python have one? A constructor initializes a new object. Java constructors share the class name, have no return type, and the compiler supplies a no-argument one only if you write none. Python uses
__init__to initialize, while__new__actually creates the object. - Q5. What is
thisin Java andselfin Python? Both refer to the current object. Java passesthisimplicitly. Python makesselfthe explicit first parameter of every instance method, and the name is a convention. - Q6. What is the difference between a class variable and an instance variable? A class (static) variable is shared by all objects, an instance variable belongs to one. In Python, assigning
obj.x = 1creates an instance attribute that hides the class attribute of the same name. - Q7. What is the difference between a static method and an instance method? An instance method needs an object. A static method belongs to the class and uses no object state (
staticin Java,@staticmethodin Python). Python also has@classmethod, which receives the class as its first argument and is used for alternative constructors. - Q8. How are objects passed to methods? Java is always pass by value, and for objects the value is a copy of the reference, so a method can change the object but cannot repoint the caller's variable. Python passes object references, so mutating a list inside a function shows outside while rebinding the name does not.
The four pillars (Q9 to Q16)
| Pillar | One-line meaning | Java tool | Python tool |
|---|---|---|---|
| Encapsulation | Hide state, expose behaviour | private fields, getters | _name convention, @property |
| Abstraction | Show what, hide how | abstract class, interface | abc.ABC, @abstractmethod |
| Inheritance | Reuse and extend a parent | extends, implements | class B(A), multiple bases |
| Polymorphism | One call, many behaviours | Overriding, overloading | Overriding, duck typing |
- Q9. What is encapsulation? Keeping data private and allowing access only through methods that can validate it. Java enforces this with
private. Python does not enforce it: a leading underscore is a convention and a double underscore only mangles the name. In the demo,a.__baldoes not exist buta._Account__baldoes. - Q10. What is abstraction, and how is it different from encapsulation? Abstraction hides complexity by exposing only what a user needs, such as
list.sort(). Encapsulation hides data to protect it. One is about the design of the interface, the other about guarding state. - Q11. What is inheritance, and what types are there? A child class gets the fields and methods of a parent. Types are single, multilevel, hierarchical, multiple and hybrid. Java allows multiple inheritance only through interfaces. Python allows multiple inheritance of classes.
- Q12. What is polymorphism? The same call behaving differently by object type. Compile-time polymorphism is overloading, and runtime polymorphism is overriding. Python adds duck typing: any object with the right method works, whatever its class.
- Q13. Method overloading versus overriding? Overloading is same name, different parameters in one class, resolved at compile time in Java. Overriding is a child redefining a parent method with the same signature, resolved at runtime. Python has no true overloading because a later
defreplaces the earlier one. Use default arguments or*argsinstead. - Q14. What is the diamond problem? A class inheriting from two parents that share a base, so it is unclear which version of a method to run. Java avoids it for classes by banning multiple class inheritance. Python resolves it with the method resolution order (MRO), the C3 linearization. In the demo, class D(B, C) printed
B>C>Aand listed the MRO as D, B, C, A, object. - Q15. What does
superdo? It reaches the parent's version of a method or constructor. Java usessuper(...)andsuper.method(). Python'ssuper()follows the MRO, so with multiple inheritance it calls the next class in line, not always the direct parent. - Q16. Can you override a static method, a private method or a constructor? In Java, no to all three. Static methods are hidden, not overridden. Private methods are not visible to subclasses and constructors are not inherited. A
finalmethod also cannot be overridden.
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self): ...
def describe(self): return f"{type(self).__name__} area {self.area():.2f}"
class Circle(Shape):
def __init__(self, r): self._r = r
def area(self): return 3.14159 * self._r ** 2
class Rect(Shape):
def __init__(self, w, h): self.w, self.h = w, h
def area(self): return self.w * self.h
try: Shape()
except TypeError as e: print("abstract:", type(e).__name__)
for s in (Circle(1), Rect(2, 3)): print(s.describe())
class A:
def hi(self): return "A"
class B(A):
def hi(self): return "B>" + super().hi()
class C(A):
def hi(self): return "C>" + super().hi()
class D(B, C): pass
print(D().hi(), [k.__name__ for k in D.__mro__])
class Account:
def __init__(self): self.__bal = 0
@property
def balance(self): return self.__bal
def deposit(self, x):
if x <= 0: raise ValueError("positive only")
self.__bal += x
a = Account(); a.deposit(50); print(a.balance, hasattr(a, "__bal"), a._Account__bal)
class Base:
def __eq__(self, o): return True
print(Base() == Base(), Base() is Base())
Output:
abstract: TypeError
Circle area 3.14
Rect area 6.00
B>C>A ['D', 'B', 'C', 'A', 'object']
50 False 50
True False
Abstract classes, interfaces and access (Q17 to Q23)
| Point | Abstract class | Interface (Java) |
|---|---|---|
| Instantiate | No | No |
| State (fields) | Yes, any | Only constants (static final) |
| Constructors | Yes | No |
| Inherit from several | No, one class only | Yes, a class can implement many |
| Method bodies | Yes | default, static, private methods since Java 8 and 9 |
| Use when | Related classes share code and state | Unrelated classes share a capability |
- Q17. Abstract class versus interface? The table above is the standard answer. In short: an abstract class models what something is and can hold state, and an interface models what something can do. Python has no
interfacekeyword, so abstract base classes ortyping.Protocolplay that role. - Q18. Can an abstract class have a constructor? Yes, in Java and Python. You cannot instantiate it directly, but the subclass constructor calls it. In the demo, calling
Shape()raisedTypeErrorbecause it has an abstract method. - Q19. What are the Java access modifiers?
private(same class), default or package-private (same package),protected(package plus subclasses) andpublic(everywhere). Python has no real modifiers, only naming conventions. - Q20. What does
finaldo in Java? Afinalvariable cannot be reassigned, afinalmethod cannot be overridden and afinalclass cannot be extended.Stringis the standard example of a final class. Python hastyping.Finalas a hint only. - Q21. What are
==and.equals()in Java, and==andisin Python? In Java==compares references for objects and.equals()compares content when overridden. In Python==calls__eq__andiscompares identity. The demo shows twoBase()objects where==isTruebecause__eq__always returns it, andisisFalse. - Q22. What is the Object class, and which methods should be overridden? In Java every class extends
Object, which suppliestoString,equalsandhashCode. OverrideequalsandhashCodetogether, because equal objects must give equal hashes or hash-based collections break. Python's equivalents are__repr__,__eq__and__hash__. - Q23. What is an immutable class? One whose state cannot change after creation, such as Java's
Stringor Python'stupleandstr. Make fieldsprivate final, set them in the constructor and expose no setters. Immutable objects are safe to share between threads.
A short Java sketch of the shape example. It was proofread, not compiled here. By the language rules it prints Rect 6.0, then Object, then String: overloads are chosen by the declared type at compile time, while area() is chosen by the real object at runtime.
abstract class Shape {
abstract double area();
String describe() { return getClass().getSimpleName() + " " + area(); }
}
class Rect extends Shape {
private final double w, h;
Rect(double w, double h) { this.w = w; this.h = h; }
@Override double area() { return w * h; }
}
class Printer {
void show(Object o) { System.out.println("Object"); }
void show(String s) { System.out.println("String"); }
}
public class Demo {
public static void main(String[] args) {
Shape s = new Rect(2, 3);
System.out.println(s.describe());
Object o = "hi";
new Printer().show(o);
new Printer().show("hi");
}
}
Design and practice (Q24 to Q32)
- Q24. Composition versus inheritance? Inheritance models an is-a relation, composition models has-a: a
Carhas anEngine. Prefer composition when you only want to reuse behaviour, because it avoids tight coupling to a parent. The usual advice is to favour composition over inheritance. - Q25. What are the SOLID principles? Single responsibility (one reason to change), open-closed (extend without editing), Liskov substitution (a subclass must work wherever its parent does), interface segregation (small focused interfaces) and dependency inversion (depend on abstractions). Interviewers usually want one example each.
- Q26. Explain the Liskov substitution principle with an example. If
SquareextendsRectanglebut changing the width also changes the height, code written for rectangles breaks. So a square is not a safe subclass here, even though it is a rectangle in geometry. - Q27. What is coupling and cohesion? Coupling is how much one class depends on another, and cohesion is how closely a class's parts belong together. Aim for low coupling and high cohesion.
- Q28. What is a design pattern? Name three. A reusable solution to a common design problem. Fresher-level examples: Singleton (one instance), Factory (create objects without naming the class) and Observer (notify subscribers of changes).
- Q29. What is dependency injection? Giving an object its collaborators from outside instead of creating them inside. It lets you swap a real database for a fake in tests. Spring does it for Java applications.
- Q30. How do exceptions fit with OOP? Exceptions are objects too, in a class hierarchy. Java splits checked and unchecked exceptions, while Python has only one family under
BaseException. Catch the most specific type and create your own exception classes for domain errors. - Q31. What is garbage collection? Automatic freeing of objects no longer reachable. Java uses a tracing collector. CPython mainly uses reference counting plus a cycle detector. Neither needs
free, but both can leak through lingering references. - Q32. How do I explain OOP in a project interview? Pick one project and name the classes, say which pillar each shows and where you chose composition. A small library or booking system with an abstract base class and two subclasses is enough. See Java interview questions and Python interview questions for language-specific follow-ups.
How to prepare
- Memorise the pillar table and the abstract class versus interface table: written tests repeat them.
- For each pillar, write ten lines of code in both Java and Python from memory.
- Be ready to explain overloading versus overriding, the diamond problem and
==versus.equals()without notes. - Pick one project and map its classes to the pillars. Ideas are in software development project ideas.
- Practise on a coding site from the coding practice websites list, then revise DSA interview questions.
Frequently asked questions
What are the most asked OOPS interview questions?
No company publishes its question bank, so this is our reading. Expect the four pillars with examples, overloading versus overriding, abstract class versus interface, the diamond problem and composition versus inheritance. Questions 3, 9, 12, 13, 17 and 24 above are the ones to master first.
What are OOPS concepts in Java and Python?
The same four pillars apply in both: encapsulation, abstraction, inheritance and polymorphism. The differences are in enforcement: Java has private and interfaces and bans multiple class inheritance. Python uses conventions, duck typing and abstract base classes, and allows multiple inheritance with an MRO.
Is Python fully object oriented?
Everything in Python is an object, including integers, functions and classes. It supports the four pillars, though it does not enforce private access or true method overloading. It also supports procedural and functional styles, so you can write Python without defining a class.
What is the difference between abstraction and encapsulation?
Abstraction is about hiding complexity behind a simple interface, so users see what an object does. Encapsulation is about hiding and protecting data inside a class. A well-designed class does both: private state, a small public interface.
How many OOPS questions should a fresher prepare?
Cover the 32 above, but go deep on about ten: the pillars, overloading versus overriding, abstract class versus interface, constructors, final and static, the diamond problem and SOLID. Depth with examples beats a long list of one-line definitions.
Do I need design patterns for a fresher OOPS interview?
Usually only names and one example of Singleton, Factory and Observer. Pattern-heavy questions belong to experienced roles. For freshers, clean explanations of inheritance, polymorphism and composition matter more.
Learn this with mentors
Programmes for builders and engineers with admissions open: live classes, mentors and project work.


