please look at the following code first...
public class Animal {
public Animal() {}
private final void run() {
System.out.println("This is a private final method in Animal!");
}
public static void eat() {
System.out.println("Animal must eat!");
}
public static void main(
String[] args) {
Animal animal = new Cat();
animal.run();
animal.eat();
}
}
class Cat extends Animal {
public Cat() {}
public static void eat() {
System.out.println("Cats like eating fish!");
}
}
In the main method of Animal, Animal animal = new Cat(); the animal variable refers to a Cat object in fact, so it should execute the method of Cat. But the Cat is the subclass of Animal, and it could neither extends the private and final methods nor see them. And to my surprise, the output is:
This is a private final method in Animal!
Animal must eat!
Besides, the static method eat in Cat must be a redefining method of Animal, not override i think.