+ 1
Object creation
If there is a super class named [Animal] and a child class named[Cat], then what is the difference between 1.Cat c=new Cat(); and 2.Animal c=new Cat() ; Pls explain.
2 ответов
0
The first one is "INHERITANCE" and the second one shows the "POLYMORPHISM"
0
if Cat has methods miau() and Animal not, in second way c can't use this method (without casting)
public class Program {
public static void main(String[] args) {
Cat c=new Cat();
c.miau();
Animal a=new Cat();
//a.miau();
}
}
class Animal {}
class Cat extends Animal {
void miau(){}
}