Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Object-Oriented Programming

    The four pillars — encapsulation, inheritance, polymorphism and abstraction — plus interfaces, equals and hashCode, enums and records.

    • Module 3 of 11
    • Intermediate
    • 12 chapters
    • 1 h 30 min

    Object-oriented design is asked in almost every Java interview and graded in every low-level design round. These ideas decide whether code stays easy to extend.

    What you will be able to do

    • Explain the four pillars with your own examples
    • Predict which method runs when classes override each other
    • Choose between an abstract class and an interface
    • Write equals and hashCode that work in collections

    Chapters

    1. EncapsulationEncapsulation — keeping an object's data private and allowing access only through methods that enforce its rules.5 min2. InheritanceInheritance lets a class — the subclass (child) — reuse and extend another — the superclass (parent) — using extends.3 min3. OverridingOverriding — a subclass provides its own version of an inherited method, with the same name and parameters.6 min4. PolymorphismOne call, many behaviours — how Java decides which method runs, and what sits on the stack and the heap while it does.34 min5. Abstract Classes (Abstraction, Part 1)Abstraction — showing only what something does, hiding how. Code that uses Question only knows "you can grade me".2 min6. Interfaces (Abstraction, Part 2)An interface is a pure contract: a list of methods a class promises to provide, using implements.6 min7. Composition Over InheritanceComposition — building a class by holding other objects as fields and delegating work to them: a "has-a" relationship.3 min8. equals and hashCode: The Contractequals decides whether two objects are logically equal (02javaclassesobjectsandmemory.md Ch 9).5 min9. Initialisation Order, final Classes and Methodsstatic { System.out.println("1. static block (class loaded)"); } // runs ONCE, when the class is first used2 min10. Nested and Anonymous ClassesA small helper who only works inside one department doesn't need a desk in the main lobby.3 min11. Enumsordinal() — position (0-based) — don't store it anywhere; reordering the constants changes it.3 min12. RecordsA printed receipt: a fixed set of facts that never changes after printing. You don't need to design a receipt from scratch each time — the2 min

    Extras