OOP — Interview-Ready Notes
Object-Oriented Programming • Core concepts • Java examples • Interview revision
How to use these notes: First understand the concept, then memorize the comparison tables and finally practice the
interview questions at the end.
1. What is OOP?
Object-Oriented Programming (OOP) is a programming paradigm in which software is designed around objects that
contain state (data) and behavior (methods). It helps organize large programs into reusable, maintainable and
extensible components.
Term
Meaning / Key Point
Class
A blueprint/template that defines data and behavior.
Object
A runtime instance of a class.
State
Values stored in an object, usually represented by fields.
Behavior
Operations an object can perform, represented by methods.
Identity
The fact that each object is a distinct runtime entity.
2. The Four Pillars of OOP
The four commonly cited pillars are Encapsulation, Abstraction, Inheritance and Polymorphism.
Term
Meaning / Key Point
Encapsulation
Bundle data and methods together and control direct access to internal state.
Abstraction
Expose essential behavior while hiding implementation details.
Inheritance
Create a new class based on an existing class and reuse/extend behavior.
Polymorphism
Allow the same interface/reference to represent different implementations.
3. Class and Object
A class defines what an object will contain and do. An object is created from that class. In Java, objects are commonly
created with new.
Term
Meaning / Key Point
Class
Logical definition; does not represent a particular instance.
Object
Actual instance with its own state; generally created at runtime.
4. Encapsulation
Encapsulation protects an object's internal state by restricting direct access and exposing controlled operations. A
common Java implementation is private fields + public methods.
5. Abstraction
Abstraction focuses on what an object does rather than how it does it. In Java, abstraction is commonly achieved
using interfaces and abstract classes.
OOP Interview-Ready Notes
Page 1
6. Inheritance
Inheritance represents an is-a relationship. A subclass inherits accessible members from a superclass and can add
or override behavior. Java supports class inheritance through extends and interface implementation through
implements.
7. Polymorphism
Polymorphism means one interface/reference can work with objects of different concrete types. The two major forms
discussed in Java interviews are compile-time polymorphism (overloading) and runtime polymorphism
(overriding).
8. Method Overloading vs Overriding
Overloading: same method name with different parameter lists, resolved at compile time.
Overriding: subclass provides a compatible implementation of an inherited instance method, resolved dynamically at
runtime when invoked through a superclass/interface reference.
Term
Meaning / Key Point
Overloading
Same class commonly; parameters must differ; compile-time resolution.
Overriding
Subclass; same signature subject to Java's overriding rules; runtime dispatch.
9. Interface vs Abstract Class
Both support abstraction, but they serve somewhat different design purposes.
Term
Meaning / Key Point
Interface
Defines a contract/capability. A class can implement multiple interfaces. Can contain abstract
methods plus default/static/private methods under Java's language rules.
Abstract class
Useful for a shared base type with common state/implementation. A class can extend only
one class.
10. Access Modifiers
Java provides four practical access levels.
Term
Meaning / Key Point
private
Accessible only within the declaring class.
default / package-private
Accessible within the same package.
protected
Accessible in the same package and, subject to Java access rules, from subclasses.
public
Accessible wherever the class/member is accessible.
11. Constructor
A constructor initializes an object when it is created. It has the same name as the class and no return type.
Constructors can be overloaded. If no constructor is declared, Java may provide a default no-argument constructor
depending on the class declaration.
12. this and super
this refers to the current object and is commonly used to distinguish fields from parameters or call another
constructor in the same class. super refers to the superclass portion of the current object and can be used to access
OOP Interview-Ready Notes
Page 2
superclass members or invoke a superclass constructor.
13. static
A static member belongs to the class rather than to each individual object. Static methods cannot directly access
instance fields/methods because they do not have an implicit object reference.
14. final
final variable: cannot be reassigned after initialization. final method: cannot be overridden. final class: cannot be
extended.
15. Association, Aggregation and Composition
These describe object relationships.
Term
Meaning / Key Point
Association
General relationship between independent objects.
Aggregation
Weak whole-part relationship; parts can exist independently of the whole.
Composition
Strong ownership/lifecycle relationship; a part is conceptually tied to the whole.
16. IS-A vs HAS-A
IS-A generally maps to inheritance/subtyping. Example: Dog IS-A Animal.
HAS-A generally maps to composition/aggregation. Example: Car HAS-A Engine.
17. Upcasting and Downcasting
Upcasting: treating a subclass object as a superclass/interface type; generally safe and implicit.
Downcasting: converting a superclass reference to a subclass reference; requires an explicit cast and can throw
ClassCastException if the object is not actually of that subtype.
18. Dynamic Method Dispatch
When an overridden instance method is invoked through a superclass/interface reference, Java selects the
implementation based on the object's actual runtime type. This is the foundation of runtime polymorphism.
19. Object Class — Important Methods
Every Java class ultimately derives from Object unless another superclass is specified. Important methods include
toString(), equals(Object) and hashCode().
Term
Meaning / Key Point
equals()
Defines logical equality when overridden appropriately.
hashCode()
Returns a hash value; equal objects must have equal hash codes.
toString()
Provides a string representation of an object.
20. equals() and hashCode() Contract
If two objects are considered equal by equals(), they must return the same hashCode(). The reverse is not required:
two unequal objects may have the same hash code. This contract is critical for hash-based collections such as
HashMap and HashSet.
OOP Interview-Ready Notes
Page 3
21. Immutable Objects
An immutable object cannot have its observable state changed after construction. Common techniques include
making the class final (when appropriate), keeping fields private/final, initializing state in the constructor, and not
exposing mutable internal state.
22. Composition over Inheritance
Prefer composition when you want to assemble behavior from independent components rather than create a strict
subtype relationship. Composition usually provides looser coupling and can make behavior easier to change or test.
23. SOLID Principles — Quick Revision
S — Single Responsibility: a class/module should have one reason to change.
O — Open/Closed: open for extension, closed for modification.
L — Liskov Substitution: subtypes should be usable wherever their base type is expected without breaking
correctness.
I — Interface Segregation: clients should not be forced to depend on methods they do not use.
D — Dependency Inversion: high-level policy should depend on abstractions rather than concrete low-level details.
24. Common OOP Interview Traps
• Encapsulation is not simply “making fields private”; it is about controlling access to state and preserving invariants.
• Abstraction and encapsulation are related but not identical: abstraction hides unnecessary complexity;
encapsulation controls access and bundles state/behavior.
• Overloading is not runtime polymorphism.
• Constructors are not inherited or overridden.
• A final reference cannot be reassigned, but the object it references may still be mutable.
• Static methods are hidden, not overridden in the same dynamic-dispatch sense as instance methods.
OOP Interview-Ready Notes
Page 4
25. Java Examples for Interviews
Encapsulation
class BankAccount {
private double balance;
public void deposit(double amount) {
if (amount > 0) balance += amount;
}
public double getBalance() {
return balance;
}
}
Inheritance + Overriding
class Animal {
void sound() {
System.out.println("Some sound");
}
}
class Dog extends Animal {
@Override
void sound() {
System.out.println("Bark");
}
}
Animal a = new Dog();
a.sound();
// Bark
Interface + Polymorphism
interface Payment {
void pay();
}
class CardPayment implements Payment {
public void pay() {
System.out.println("Pay by card");
}
}
class UpiPayment implements Payment {
public void pay() {
System.out.println("Pay by UPI");
}
}
Payment p = new UpiPayment();
p.pay();
// Pay by UPI
Overloading
class Calculator {
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
}
Composition
class Engine {
void start() {
System.out.println("Engine started");
}
}
OOP Interview-Ready Notes
Page 5
class Car {
private final Engine engine = new Engine();
void startCar() {
engine.start();
}
}
26. Frequently Asked Interview Questions
1. What is OOP and why is it useful?
2. Explain the four pillars of OOP with real-world examples.
3. What is the difference between a class and an object?
4. Explain encapsulation and how you implement it in Java.
5. Abstraction vs encapsulation — what is the difference?
6. What is inheritance? What problems can inheritance create?
7. What is polymorphism? Explain compile-time and runtime polymorphism.
8. Overloading vs overriding?
9. Can a constructor be overridden? Why?
10. Can static methods be overridden?
11. Interface vs abstract class?
12. Why does Java not support multiple inheritance of classes?
13. What is upcasting and downcasting?
14. Explain dynamic method dispatch.
15. Why must equals() and hashCode() be consistent?
16. What is an immutable class? How would you design one?
17. Aggregation vs composition?
18. IS-A vs HAS-A relationship?
19. Why is composition often preferred over inheritance?
20. Explain SOLID principles with examples.
27. One-Page Rapid Revision
Concept
Remember
OOP
Objects = state + behavior
Encapsulation
Hide/control internal state
Abstraction
Expose essentials; hide implementation
Inheritance
Reuse/extend via IS-A
Polymorphism
One interface, many implementations
Overloading
Different parameters; compile-time
Overriding
Subclass implementation; runtime dispatch
Interface
Contract/capability; multiple interfaces possible
Abstract class
Shared base state/behavior + abstraction
Composition
HAS-A; often lower coupling
equals/hashCode
Equal objects → same hash code
OOP Interview-Ready Notes
Page 6
Concept
Remember
final
Variable: no reassignment; method: no override; class: no extension
Interview tip: For every OOP concept, prepare four things: definition → why it is needed → simple Java example →
real-world example. This structure keeps answers concise and technically strong.
OOP Interview-Ready Notes
Page 7