I was testing around polymorphism, and I came up with below code:
public abstract class Animal {
}
public interface Hunter {
}
public class Cat extends Animal implements Hunter {
}
public class Tiger extends Cat {
public static void main(String[] args){
//n1
}
}
I placed on n1:
ArrayList<Tiger> myList = new ArrayList<>();
myList.add(new Cat());
But it fails to compile: I think that it does because Cat is parent of Tiger, and Tiger can only store its children which at the moment it does not have any.
Am I overlooking the real cause of this issue?