public class Fruit {
public String getName() {
return "Fruit";
}
}
public class Apple extends Fruit {
@Override
public String getName() {
return "Apple";
}
}
public class Test {
public static void main(String[] args) {
Fruit father = new Fruit();
Fruit son = new Apple();
Apple apple = new Apple();
System.out.println(father.getName()); // "Fruit"
System.out.println(son.getName()); // "Apple"
System.out.println(apple.getName()); // "Apple"
}
}