Object-Oriented Java
Constructors, the four pillars, overloading vs overriding, relationships between classes, generics, reflection and object equality. Classes and objects, inheritance, interfaces and abstract classes and generics have their own pages earlier in this subject.
This is an overview — pick a sub-topic below.
Sub-topics (14)
Constructors in Java
Special methods that initialise new objects; same name as the class, no return type.
Polymorphism in Java
A reference of a parent type can point to any subclass, and overridden methods run the subclass version.
Encapsulation in Java
Keep fields private and control access through methods to protect invariants.
Abstraction in Java
Expose what an object does while hiding how — via interfaces and abstract classes.
Method Overloading
Several methods with the same name but different parameter lists, chosen at compile time.
Method Overriding
A subclass provides its own version of an inherited method, chosen at run time.
Composition
Build classes from other objects ("has-a") instead of inheriting ("is-a").
Association
A general relationship where objects use or know each other, each with its own lifecycle.
Aggregation
A "whole-part" association where parts can exist independently.
Reflection
Inspect and use classes, methods and fields at run time.
The Object Class
The root of every class: `equals`, `hashCode`, `toString`, `getClass`, `clone`, `wait`/`notify`.
equals and hashCode
Equal objects must have equal hash codes — override both together.
Comparable
Defines a class's natural ordering via `compareTo`.
Comparator
An external ordering object, composable with helper methods.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.