I currently read a java book and I am stuck at an example including this line :
Bird titi = new Swan();
where Swan is a subclass of Bird.
I could explain this as follow:
when java executes this line, it stores memory for the value titi, and the memory stored can contain an information for an object of type Bird. next, the second part of the line call the Swan constructor without any argument, which initializes the titi value.
if I am right, I can't explain why a Swan instance can be stored in a Bird type because Swan, as a subclass, contains more information than Bird. so I think I am something wrong. where?
and, extra-question : in which case this type of statement is useful?
thank you