SE450: Review: OO Mechanisms: Subclassing (Inheritance) [17/25] Previous pageContentsNext page

(Partial) responsibility for a message is given to a class other than the actual class of the object.

The receiving object's actual class inherits a method, or it explicitly invokes method of an ancestor class, perhaps doing some processing before and after the call.

class C { public void m() { System.out.println("C.m"); }
class D extends C {
  public void f() { this.m(); System.out.println("D.f"); }
  // pure inheritance of m
class Main {
  public static void main(String[] args) {
    D x = new D();
    x.f(); // prints "C.m D.f"
    x.m(); // prints "C.m"

Previous pageContentsNext page