Well, you could specify a s1 link of type Graduate . The main advantage you get when declaring a super type link is the power of polymorphism.
With a reference to a supertype pointing to a subclass object, you can bind the same link to several objects of the subclass. And the actual method invoked will be determined at runtime, based on which object they point to. But the main condition for this is that this method must also be defined in a subclass, otherwise the compiler will not be able to find the method declaration.
Here you were forced downcast because you did not define a method in the superclass. Because the compiler cannot determine the definition of this method in the Student class. He has no idea what the actual object s1 points to. Remember that the compiler checks the type of link to find a meethod declaration.
In general, whenever you see that you are suppressing a subclass in your code, it is almost always a sign of something wrong (there are exceptions). And you have to change your classes.
See how you will benefit by using a superclass link instead of a subclass link:
For example, suppose you have another subclass of the Student class like:
class Phd extends Student { getResearchTopic(){...} }
and you also provide a definition (default) in the Student class:
class Student { getResearchTopic(){...} }
Now you create the following two objects that the Student link points to:
Student student = new Phd(); student.getResearchTopic();
So, with just one link, you get access to subclass-specific methods.
You can see one of the main implementations of this function in the factory method template, where one static method returns an object of different subclasses based on some condition:
public static Student getInstance(String type) { if (type.equals("graduate")) return new Graduate(); else if (type.equals("phd")) return new Phd(); }
So you can see that the same method returns an object from different subclasses.
All the things listed above can be done only according to one concept:
A reference to a superclass can refer to any objects of a subclass, but not vice versa.