Units 5 and 9 cover the heart of Java — object-oriented programming. Students learn to write their own classes, use encapsulation, and leverage inheritance and polymorphism.
Class: blueprint for objects. Instance variables: private (encapsulation). Constructor: initialises object. Accessor methods (getters): return instance variable values. Mutator methods (setters): modify values. Static methods/variables: shared by all instances, called on the class itself. this keyword: refers to current object. Method overloading: same name, different parameters. Scope: local variables vs instance variables.
Inheritance: class extends parent. Subclass inherits public methods/variables. super(): calls parent constructor (must be first line). super.method(): calls parent\'s version. Method overriding: subclass provides its own implementation (same signature). Polymorphism: parent reference can hold child object. Method called depends on actual object type (dynamic binding). Object class: all classes inherit from Object. toString(): string representation. Abstract classes cannot be instantiated. Interfaces define contracts.
Polymorphism means "many forms" — a parent class reference variable can hold objects of any subclass, and when a method is called, the actual subclass\'s version executes (not the parent\'s). Example: Animal a = new Dog(); a.speak() calls Dog\'s speak(), not Animal\'s. This is useful because: (1) You can write generic code that works with any subclass (e.g., an ArrayList<Animal> can hold Dogs, Cats, Birds). (2) New subclasses can be added without changing existing code. (3) It enables the design principle "program to an interface, not an implementation." On the AP exam, polymorphism questions test whether you can determine which version of an overridden method is called.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →