SE450: Overriding: Code Inheritance [8/35] Previous pageContentsNext page

A subclass can inherit code from its superclass.

class B {
  void f() { ... }
}
class D extends B {
  void g() { ... }
}
class Main {
  public static void main(String[] args) {
    D x = new D();
    x.g();  // executing code from D
    x.f();  // executing inherited code from B
  }
}

Previous pageContentsNext page