--- title: Core Pillars collection: Java Oops author: Suraj Kumar Jha updated: 2026-09-29 source: https://docs.chaicode.com/java-oops/core-pillars --- # Core Pillars ![A diagram showing a parent box 'DeliveryApp' with an arrow pointing down to child box 'Blinkit'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/375d81b9b7a39df6742cf001a8ff8fba82f5fa7193da7f1db231ae0a49a9c0c5.jpg) Inheritance: Reusing Code — 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. ![Code sketch showing child constructor calling super(baseFee) on the first line.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/a7bf7dd3f810711b6a97f403720dd61da6a26f7de6b188da94cbba5bbbc69f52.jpg) The extends & super Keywords — 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. ![A split box showing base DeliveryApp fee logic vs Zepto's customized zero-fee logic.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/54f382485bf2c58090be0f491b171d8d2dc5eb7aa4482d84eb91210669adcf1f.jpg) Method Overriding Basics — 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. ![A Swiggy payment screen with one 'Pay' button fanning out to PhonePe UPI, Card OTP, and Paytm Wallet.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/51589a0ca287592dc296e922258423ecc78f990ed5efb7364221bc2e934e8bf0.jpg) Polymorphism: Many Forms — 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). ![Flipkart search bar icon pointing to three overloaded search() functions with different parameter counts.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/3b11396e6b027edb1f535b3d3707a5bf6bb7997a097eb7b9d7441dcf3e8bb4c7.jpg) Compile-Time Polymorphism (Overloading) — 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. ![Variable 'p' of type Payment pointing dynamically to a 'PhonePe' object in memory.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/2a82ddfc1c879a3feab550bf1d3e1fe2b8ad6c9ee0c95df1e3bbf9dc4ba1bac4.jpg) Runtime Polymorphism (Overriding) — 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. ![A 2-column side-by-side comparison table for Overloading vs Overriding.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/40cd70ba7f87adc6b3c5dede920b2ef4bf2a2d7d2b8e20cabf380941f7c87280.jpg) Overloading vs Overriding — 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. ![User tapping 'Book Ticket' on IRCTC app, with complex backend servers hidden inside a cloud outline.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/b4446ac6221ab9a142257aba995a3cf5fefe93b070765a57e42b7f4b55f1628d.jpg) Abstraction: Hiding Details — 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. ![Class OlaCab inheriting from Cab class and implementing GPSLocatable and Payable interfaces.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/f464f27ebfca5442c666bab69661716ca6c0c6c8e817096e3c77b43aedbd4ce0.jpg) Abstract Class vs Interface — 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. ![Diagram contrasting 'Rapido extends Transport' (IS-A) against 'ZomatoOrder contains Partner + Restaurant' (HAS-A).](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/999904fd28f5ebbc0ab17f3f04984c2153227e960d442e007016a221abee12bd.jpg) Composition vs Inheritance — 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.