Suppose I have an abstract class Person. There is another class Student which extends Person. But the Student class has a member variable, say college of type String, which is not there in Person class.
We know that we can reference a subclass from a superclass, for example,
Person p = new Student();
Will the object p have the member college?
You won’t be able to do
p.college. However, you can cast it toStudentand in this case it will have: