chaidocs
Java Oops

Core Pillars

Suraj Kumar Jha 10 pages 2 min read Updated Sep 29, 2026
On this page
  1. Inheritance: Reusing Code
  2. The extends & super Keywords
  3. Method Overriding Basics
  4. Polymorphism: Many Forms
  5. Compile-Time Polymorphism (Overloading)
  6. Runtime Polymorphism (Overriding)
  7. Overloading vs Overriding
  8. Abstraction: Hiding Details
  9. Abstract Class vs Interface
  10. Composition vs Inheritance

Inheritance: Reusing Code

01 A diagram showing a parent box 'DeliveryApp' with an arrow pointing down to child box 'Blinkit'.
Notes
Inheritance lets a child class acquire properties and behavior from a parent class. It eliminates code duplication across similar features. Example: Blinkit IS-A DeliveryApp. Blinkit automatically gets core features like login() and trackOrder() from DeliveryApp.

The extends & super Keywords

02 Code sketch showing child constructor calling super(baseFee) on the first line.
Notes
extends connects child class to parent class (e.g., class Blinkit extends DeliveryApp). super refers directly to the immediate parent class. Use super() to call the parent's constructor before adding child-specific features. Important: super() must always be the very first statement in a constructor.

Method Overriding Basics

03 A split box showing base DeliveryApp fee logic vs Zepto's customized zero-fee logic.
Notes
Occurs when a child class rewrites a parent method to give its own implementation. Parent DeliveryApp defines calculateFee(). Zepto overrides calculateFee() to offer free delivery on orders above ₹199. Java executes the method based on the actual object created.

Polymorphism: Many Forms

04 A Swiggy payment screen with one 'Pay' button fanning out to PhonePe UPI, Card OTP, and Paytm Wallet.
Notes
Polymorphism means 'one name, multiple behaviors'. Allows a single interface to handle different underlying operations. Example: The 'Pay' button on Swiggy behaves differently for UPI, Credit Card, or Paytm. Two main types: Compile-Time (Overloading) and Runtime (Overriding).

Compile-Time Polymorphism (Overloading)

05 Flipkart search bar icon pointing to three overloaded search() functions with different parameter counts.
Notes
Multiple methods in the same class share the exact same name. They MUST have different parameters (count, type, or sequence). Example: Flipkart search("IPhone") vs search("Mobiles", 50000). The compiler decides which method to run based on passed arguments.

Runtime Polymorphism (Overriding)

06 Variable 'p' of type Payment pointing dynamically to a 'PhonePe' object in memory.
Notes
A parent reference points to a child object at runtime. Example: Payment p = new PhonePe(); Both parent and child share the same method signature pay(). Java checks the actual object at runtime and triggers PhonePe's UPI PIN screen.

Overloading vs Overriding

07 A 2-column side-by-side comparison table for Overloading vs Overriding.
Notes
Overloading: Same class, same method name, DIFFERENT parameters (Compile-Time). Overriding: Parent-Child classes, same method name, SAME parameters (Runtime). Overloading does NOT require inheritance; Overriding REQUIRES inheritance. Overloading changes inputs; Overriding replaces logic completely.

Abstraction: Hiding Details

08 User tapping 'Book Ticket' on IRCTC app, with complex backend servers hidden inside a cloud outline.
Notes
Abstraction exposes WHAT an object does while hiding HOW it works internally. Keeps user interface simple and hides background complexity. Example: Booking a ticket on IRCTC app with a single click. You don't see backend database locks, seat allocation logic, or railway servers.

Abstract Class vs Interface

09 Class OlaCab inheriting from Cab class and implementing GPSLocatable and Payable interfaces.
Notes
Abstract Class (extends): Best for related classes sharing state/code (e.g., base Cab for Ola/Uber). Interface (implements): A strict contract for capabilities (e.g., GPSLocatable, Refundable). A class can extend only ONE class, but can implement MULTIPLE interfaces. Interfaces cannot hold instance states; Abstract classes can.

Composition vs Inheritance

10 Diagram contrasting 'Rapido extends Transport' (IS-A) against 'ZomatoOrder contains Partner + Restaurant' (HAS-A).
Notes
Inheritance models an 'IS-A' relationship (Rapido IS-A TransportService). Composition models a 'HAS-A' relationship (ZomatoOrder HAS-A DeliveryPartner). Composition joins independent objects together, making code flexible and loosely coupled. Design Rule: Prefer Composition over Inheritance for easier changes later.