这里的变量a
和b
的对象的行为是否有区别?
class Animal {
public void makeSound() {
System.out.println("Grr...");
}
}
class Dog extends Animal {
public void makeSound() {
System.out.println("Woof");
}
}
class Program {
public static void main(String args[ ]) {
Animal a = new Dog();
Dog b = new Dog();
a.makeSound();
b.makeSound();
}
}