Overloading a base-class method name in a derived class does not hide the base-class versions : Overloading « Class « Java






Overloading a base-class method name in a derived class does not hide the base-class versions

Overloading a base-class method name in a derived class does not hide the base-class versions
// : c06:Hide.java
// Overloading a base-class method name in a derived class does not hide the base-class versions.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

class Homer {
  char doh(char c) {
    System.out.println("doh(char)");
    return 'd';
  }

  float doh(float f) {
    System.out.println("doh(float)");
    return 1.0f;
  }
}

class Milhouse {
}

class Bart extends Homer {
  void doh(Milhouse m) {
    System.out.println("doh(Milhouse)");
  }
}

public class Hide {
  public static void main(String[] args) {
    Bart b = new Bart();
    b.doh(1);
    b.doh('x');
    b.doh(1.0f);
    b.doh(new Milhouse());
  }
} ///:~



           
       








Related examples in the same category

1.Demonstration of both constructor and ordinary method overloadingDemonstration of both constructor and ordinary method overloading
2.Overloaded constructor
3.Overloaded methodOverloaded method
4.Demonstration of overriding fieldsDemonstration of overriding fields
5.Overloading based on the order of the argumentsOverloading based on the order of the arguments
6.Promotion of primitives and overloadingPromotion of primitives and overloading
7.Demotion of primitives and overloading