Suppose we have the following code snippet:
Cat cat = new Cat(); // The Cat class extends Animal
ArrayList<Animal> animalList = new ArrayList<>();
animalList.add(cat);
catis a reference of typeCatthat points to an object of typeCatanimalList.get(0)is a reference of typeAnimalthat points to the same object as the cat reference.cat == animalList.get(0)will evaluate totruesince they are both pointing to the same object.
However, one reference is of type Cat and the other of type Animal(position 0 in list), so am I wrong in saying that the references are not entirely equal, even though they point to the same memory location? Am I looking into the terminology too much?