programming-examples/java/Core_Java/Method Overriding.java

23 lines
463 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Method Overriding
class A {
String name() { return "A"; }
}
class B extends A {
String name() { return "B"; }
}
class C extends A {
String name() { return "C"; }
}
public class Overriding {
public static void main(String[] args) {
A[] tests = new A[] { new A(), new B(), new C() };
for (int i = 0; i < tests.length; i++)
System.out.print(tests[i].name());
}
}