Object-Oriented Programming in Java
Lessons in this section
- Classes and Objects
Create your own types with classes, make objects with new, use fields, methods, this and constructors, control access with modifiers, and see objects on the stack and heap.
- Static Members
Share data and behaviour across a whole class with static variables, static methods and static blocks, and learn why main is static.
- Advanced Classes
Organise code with static nested, inner, local and anonymous classes, and control extension with final and sealed classes.
- Enums and Records
Model fixed sets of choices with enums, including fields, constructors and methods, and carry immutable data with records.
- Interfaces
Describe abilities with interfaces: declare and implement them, implement several at once, add default and static methods, and use functional interfaces with lambdas.
- Inheritance
Reuse code with inheritance: parent and child classes, the IS-A test, types of inheritance, extends, super and constructor chaining.
- Polymorphism
Use one name for many behaviours with overloading and overriding, @Override, dynamic method dispatch, and safe upcasting and downcasting.
- Abstraction
Hide details and show only what matters with abstract classes, abstract methods and interfaces, and choose between them.
- Encapsulation
Protect object data with private fields, getters and setters, validation and read-only patterns, and see how encapsulation differs from data hiding.