Student is a Person, but a Person is not necessarily a Student. A Person could be a Teacher, Staff, etc.
In general there's no way for the compiler to know before-hand if a Person variable does...
Type: Posts; User: helloworld922
Student is a Person, but a Person is not necessarily a Student. A Person could be a Teacher, Staff, etc.
In general there's no way for the compiler to know before-hand if a Person variable does...
student2 is a variable of type Person, which holds a Student object which happens to also be a Person (due to polymorphism).
You can check this quite handily using the instanceof method:
...