For example lets say I have a Car
super class and a Honda
sub class extending from Car
.
I understand I can create a Honda
object by:
Honda accord = new Honda();
and I can also do:
Car accord = new Honda();
But what are the advantages to instantiating accord as a Car type?
I know if I want to search all Car subclasses I can use if (var instanceof Car)
, but aside from this are there any special cases?
I'm just having difficulty wrapping my head around this.
Thank You.