Image

Imageandrogy8 wrote in Imagejava_dev

variable declarations and class hierarchies

I'll just jump right into this...

Suppose there is a class hierarchy such that Person is the parent class, Athlete is a subclass of Person, and SoccerPlayer is a subclass of Athlete.

That would mean the following declarations would be valid:
Person a = new Athlete();
Person sp = new SoccerPlayer();

I am wondering if there would be any advantage to those declarations as opposed to the easier-to-read  in-my-opinion declarations:
Athlete a = new Athlete();
SoccerPlayer sp = new SoccerPlayer();