$ Java OOP Concepts
// Interview Prep — Quick Reference
Quick Reference
Class
Blueprint / Template — Variables & Methods
Object
Instance of a Class
Encapsulation
Data Hiding — Wraps Data + Methods
Inheritance
Code Reusability — IS-A Relationship
Polymorphism
One Interface, Many Forms
Abstraction
Hide Implementation Details
Legend
Encapsulation
Inheritance
Polymorphism
Abstraction
Class / Object
Modifiers / Relationships
Relationship Types (HAS-A)
Association HAS-A, fully independent — Teacher ↔ Student
Aggregation Weak HAS-A, parts exist independently — Department ↔ Employee
Composition Strong HAS-A, parts can't exist alone — Car ↔ Engine
Four Pillars of OOP
1. Encapsulation
Wrapping data and methods together into a single unit; achieved using private variables with public getters/setters.
Data Hiding Security Maintainability
Ex: private balance + getBalance()
2. Inheritance
Child class inherits properties & behavior from a parent class, promoting code Reusability.
Single Multilevel Hierarchical Multiple (via Interface)
Ex: class Dog extends Animal
3. Polymorphism
One interface, many forms — the same action behaves differently on different objects.
Compile-Time (Overload) Runtime (Override)
Ex: Person is Employee, Patient & Father at once
4. Abstraction
Showing only essential details and hiding implementation complexity from the user.
Abstract Class Interface
Ex: car.start() hides engine internals
Structure & Examples
Class / Object & Inheritance Example
│ │ ├── Class (Blueprint): Defines variables (state) + methods (behavior) │ └── Object = Instance of Class, created via new keyword │ ├── Inheritance (IS-A): child reuses parent's members │ ├── Single: Dog extends Animal │ ├── Multilevel: Puppy extends Dog extends Animal │ ├── Hierarchical: Dog, Cat both extend Animal │ └── Multiple (via Interface): class Duck implements Flyable, Swimmable │ └── Polymorphism: same call, different behavior ├── Compile-Time — Method Overloading: add(int,int) vs add(int,int,int) └── Runtime — Method Overriding: Animal.speak() → Dog.speak() @Override
Abstraction: Interface vs Abstract Class
│ │ ├── Interface: 100% Contract — "What to do" │ ├── Variables: public static final (constants only) │ ├── Methods: Abstract, Default, Static │ └── Inheritance: A class can implement multiple interfaces │ └── Abstract Class: Partial Implementation — "What + How (partial)" ├── Constructor: Allowed (called via super()) ├── Methods: Abstract + Concrete methods together └── Inheritance: A class can extend only one abstract class
Comparisons & Access Control
Abstract Class vs Interface
FeatureAbstract ClassInterface
ConstructorYesNo
VariablesAny Typepublic static final
MethodsAbstract + ConcreteAbstract, Default, Static
InheritanceSingleMultiple
StateYesNo
Overloading vs Overriding
Overloading
WhenCompile-Time Polymorphism
RuleSame name, diff signature
Varies byNumber / Type / Order of Params
ClassSame class
Overriding
WhenRuntime Polymorphism
RuleSame signature, same/covariant return
Varies byImplementation in Child Class
ClassParent → Child (@Override)
Access Modifiers
ModifierSame ClassPackageChildOutside
privateYesNoNoNo
defaultYesYesNoNo
protectedYesYesYesNo
publicYesYesYesYes
Constructors
TypeDescription
Default ConstructorNo-arg; auto-supplied by compiler if none defined; initializes with default values
Parameterized ConstructorAccepts arguments to initialize object state at creation time
PurposeInitialize object state as soon as it's created