Unit 3

OOP Concepts

The core of OOP in Java: classes and objects, constructors and overloading, memory and garbage collection, modifiers, encapsulation, inheritance, polymorphism, abstraction, abstract classes and interfaces.

What you will learn

After this unit you can:

Topics in this unit

3.1Classes and Objects✓3.1.1Classes and objects in the real world1 diagram✓3.1.2Attributes and methods1 code example✓3.1.3Creating objects and accessing members1 code example · 1 diagram✓3.1.4The this keyword and constructors3 code examples✓3.1.5Destructors and releasing resources2 code examples✓3.1.6Overloading1 code example · 1 diagram✓3.1.7Static members and a complete program1 code example✓3.1.8Self-check and practice✓3.2Memory Management in OOP✓3.2.1Stack, heap and dynamic allocation2 code examples · 1 diagram✓3.2.2Garbage collection and the object lifecycle1 code example · 1 diagram · interactive lab✓3.2.3Self-check and practice✓3.3Modifiers✓3.3.1Access modifiers1 code example · 1 diagram · interactive lab✓3.3.2Non-access modifiers2 code examples · 1 diagram✓3.3.3Self-check and practice✓3.4Encapsulation1 diagram✓3.4.1Getters, setters and validation1 code example✓3.4.2Self-check and practice✓3.5Inheritance✓3.5.1The extends and super keywords1 code example · 1 diagram✓3.5.2Hierarchies and types of inheritance2 diagrams✓3.5.3Multiple inheritance and the diamond problem1 code example · 1 diagram✓3.5.4Method overriding1 code example✓3.5.5Constructor order1 code example · 1 diagram✓3.5.6Self-check and practice✓3.6Polymorphism✓3.6.1Compile-time and run-time polymorphism✓3.6.2Run-time polymorphism in action1 code example · 1 diagram✓3.6.3Upcasting, downcasting and instanceof1 code example · 1 diagram✓3.6.4Self-check and practice✓3.7Abstraction1 diagram✓3.8Abstract Classes and Interfaces✓3.8.1Abstract classes1 code example✓3.8.2Interfaces1 code example✓3.8.3Abstract class or interface?1 diagram✓3.8.4Self-check and practice✓3.9Real-World Examples of Encapsulation and Abstraction1 code example · 1 diagram✓