SE450: Overriding: Overriding versus Hiding [11/35] Previous pageContentsNext page

Unlike hiding, overriding can affect the behavior of a superclasses.

In the following example, the behavior of m is the same in both classes, using B.x in both cases.

class B {
  int x;
  void m() {...use x..}
}
class D extends B {
  float x;
  // ...inherit m...
}

In the next example, the behavior of m is different in the two classes, since B.m will use B.f, but D.m will use D.f.

        
class B {
  int f() {...}
  void m() {...use f..}
}
class D extends B {
  int f() {...}
  //...inherit m...
}

Previous pageContentsNext page