40 lines
696 B
Java
40 lines
696 B
Java
![]() |
//: reuse/Hide.java
|
|||
|
// <20>2015 MindView LLC: see Copyright.txt
|
|||
|
// Overloading a base-class method name in a derived
|
|||
|
// class does not hide the base-class versions.
|
|||
|
import static com.mindviewinc.util.Print.*;
|
|||
|
|
|||
|
class Homer {
|
|||
|
char doh(char c) {
|
|||
|
print("doh(char)");
|
|||
|
return 'd';
|
|||
|
}
|
|||
|
float doh(float f) {
|
|||
|
print("doh(float)");
|
|||
|
return 1.0f;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
class Milhouse {}
|
|||
|
|
|||
|
class Bart extends Homer {
|
|||
|
void doh(Milhouse m) {
|
|||
|
print("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());
|
|||
|
}
|
|||
|
} /* Output:
|
|||
|
doh(float)
|
|||
|
doh(char)
|
|||
|
doh(float)
|
|||
|
doh(Milhouse)
|
|||
|
*///:~
|