Simple Class Hierarchy - B subclasses A
Previous    Next    Home    Source    Package

  1. Class B subclasses A via
       class B extends A {
  2. Class B inherits some of the local state and all methods of A. Class B does not inherit int number from A because it has its own such variable. Class B inherits int state from A because it has no variable of the same name and type.
  3. The constructor of class B invokes the constructor of class A via
       public B (int n) { super(n); }
    This results in the variable number of A taking the value that was passed to the constructor of B. But number of B hides number of A. So, to get access to number of A we must use method getNumberFromA().
  4. Although method rand is not defined in class B, an object of class B may invoke it through class A. So, it is class A's rand method that B uses.