I have a confusion please help
class Animal {
public void move() {
System.out.println("Animals can move");
}
}
class Dog extends Animal {
public void move() {
System.out.println("Dogs can walk and run");
}
}
public class TestDog {
public static void main(String args[]) {
Animal a = new Animal(); // Animal reference and object
**Animal b = new Dog(); // Animal reference but Dog object**
a.move(); // runs the method in Animal class
b.move(); // runs the method in Dog class
}
}
while creating Animal reference but Dog object we could have done
Dog b = new Dog();
and we would have the same result, so i just wanted to know whats the difference and when do we use it?