What is the benefit using different type when creating an object in java?
If i have 2 classes:
public class Animal {
public Animal() {
}
public void move() {
System.out.println("Moving...");
}
}
public class Bird extends Animal {
public Bird() {
}
public void fly() {
System.out.println("Flying...");
}
}
When i should use:
Animal bird1 = new Bird();
and
Bird bird2 = new Bird();
I still can not understand if Bird extends Animal, why using Animal as variable type?