Your line 2 would be OK, though, if you changed the definition of Child to:
In that case, because a Child IS-A Parent, you can assign it to a Parent reference variable. Everything still works because of polymorphism.
Welcome to the JavaRanch . Perhaps you would understand better by the following one.
If we have a Parent Child relationship like below(ie)Child extends Parent), we can create objects for those classes as follows.
Possible Ways :
The impossible way is
The reason is that
1.)Parent class can create an object of its own and use its variables and methods.(By default all classes extend to Object class)
2.)A child class can also create an own object of it like the parent class.
3.)When a child class extends to a parent class, it can create an Object of itself while it's Reference can point to Super class Object(in this case the Parent class) , since it inherits properties from the Parent class .
4.) A Parent class will not know it's child classes behaviours & properties. So it's impossible to refer it's object to it's child class.
"Learning is a Culture where your Eagerness & Curiosity plays a major Role".