With the code below:
public class Animal {
....// class stuff here
}
public class Cat extends Animal {
....// class stuff here
}
When trying to create a new Cat object, what is the difference between?:
Cat myCat = new Cat(); //and
Animal myCat = new Cat();
I've read previously with lists that you should declare the most generic on the left (i.e.
List<String> = new LinkedList<String>();
) so that if ever you want to change the implementation to use an ArrayList instead, there's less code to change.
Does it follow in ALL cases that you should always declare the most generic (least specific) on the laft (in this case Animal myCat = new Cat();
)?