Oracle Java SE 21 study materials
Oracle Java SE 21 study resources

Oracle Java SE 21: Using Object-Oriented Concepts in Java

Oracle Java SE 21 · Work through your exam, one topic at a time.

All guide sections

Using Object-Oriented Concepts in Java

Class design

Know the pillars concretely: encapsulation (private fields plus accessors), inheritance (single class extends, multiple interface implements), polymorphism (virtual dispatch through the reference type), abstraction (abstract classes, interfaces). Constructor chaining via this(...)/super(...) must be the first statement; if you omit super(), the compiler inserts a no-arg call, which fails when the parent has no no-arg constructor. Initialization order: static fields/blocks (parent then child), instance initializers and field initializers in declaration order (parent then child), then constructor bodies.

Overriding vs overloading

Overriding requires the same signature, a covariant return type, no reduced visibility, and no broader checked exceptions. static, private and final methods cannot be overridden (static methods are hidden). Overload resolution prefers exact match, then widening, then boxing, then varargs - so m(long) beats m(Integer) for an int argument.

Modern types

A record is final, implicitly extends Record, and gets a canonical constructor, equals/hashCode/toString, and accessors named after the components (x()). A compact constructor validates without repeating the parameter list. Records may implement interfaces and declare static members but cannot declare instance fields. enum constants are implicitly public static final; enums may have private constructors, fields, and constant-specific class bodies. sealed types list permits subtypes that must be final, sealed, or non-sealed. Interface fields are implicitly public static final; default, static and private methods are allowed.

Worked rule: with @Override absent, a "overriding" method with a different parameter list is only an overload - a favourite source of surprise output.