Polymorphism & Inheritance
Master compile-time and runtime polymorphism: method overloading, passing and returning objects, recursive stack tracing, static & final members, inner classes, inheritance types, super, constructor chaining order, method overriding, and dynamic method dispatch.
Box -> BoxWeight -> Shipment), super, dynamic method dispatch diagram, and final with inheritance.Section 1: Polymorphism
Polymorphism & Method Overloading (Compile-Time Binding & Resolution Rules)
In C, computing the absolute value of an int, long, and double required memorizing three distinct function names (abs(), labs(), fabs()). Java eliminates that clutter through Polymorphism ('many forms'), starting with Compile-Time Method Overloading—letting one clean method name (Math.abs() or area()) handle multiple parameter combinations intelligently.
Objects as Parameters, Returning Objects & Java Argument Passing Semantics
Methods don't just exchange int or double values—they routinely accept whole objects as parameters (for example, comparing two objects or constructing a clone) and manufacture new objects as return values. Understanding what happens to object references when passed into a method is essential for code-tracing questions!
Recursion in Java: Base Case, JVM Stack Tracing & Unwinding
Recursion is a powerful problem-solving technique where a method breaks a problem into smaller identical subproblems by calling itself. In KTU exams, you are frequently asked to define recursion, explain what happens inside the JVM Stack during recursive calls, and trace outputs for Factorial, Fibonacci, or reverse-printing routines.
Static Members (Variables, Methods, Blocks) & Final Variables
Most variables and methods belong to individual objects (s1.name, s2.name). But sometimes a property—like a shared college name, a total object counter, or mathematical PI—belongs to the entire class or must never change. Java handles class-level sharing with static and immutability of constants with final.
Inner Classes in Java: Types, Access Rules & Syntax
Sometimes one helper class only makes logical sense inside another class—for example, a button click listener tied tightly to one window, or an internal iterator belonging to a data structure. Java allows nesting a class inside another class (Nested / Inner Classes), giving it privileged access even to the outer class's private members!
Section 2: Inheritance
Inheritance Fundamentals, `extends` & Types of Inheritance (incl. Multiple/Hybrid Limitations)
Why rewrite name, age, and displayBasicInfo() separately inside Student, Teacher, and Doctor? Inheritance lets you place shared traits in a general Superclass (Person) and create specialized Subclasses (Student extends Person) that automatically inherit those members and add only what is unique—creating clean hierarchical classifications.
The `super` Keyword & `protected` Members in Inheritance
When a superclass keeps its fields private (for encapsulation) or when a subclass declares a field/method with the same name as its parent, how can the subclass initialize those hidden parent variables or invoke the parent's version? Java provides the **super keyword—plus the protected modifier** when you intentionally want subclasses across packages to inherit controlled access.
Constructor Calling Order & Execution in Multilevel Inheritance
When you create an object of a subclass at the bottom of a multilevel chain (like Shipment extends BoxWeight extends Box), multiple constructors run—one for every class in the hierarchy! Knowing the exact order in which those constructors are invoked vs completed is one of the highest-yield tracing topics in Module 2.
Method Overriding, Dynamic Method Dispatch (Runtime Polymorphism) & Overloading vs Overriding
Dynamic Method Dispatch—powered by Method Overriding—is the crown jewel of Object-Oriented Programming in Java. It allows you to write general algorithms against a single superclass (Figure or Shape) while subclasses (Rectangle, Triangle) supply specialized implementations selected automatically at runtime!
Using `final` with Inheritance: `final` Methods, `final` Classes & Performance
Inheritance is powerful, but sometimes an architect intentionally locks a method's security check or locks an entire class (like java.lang.String) so nobody can create malicious or buggy subclasses. The **final keyword** gives you that exact lock at three levels: constants, methods, and classes.