Hello Hemant,
Always remeber one thing ,
Parent class object can hold object of child class.
e.g.
public class ParentChildClass{
public static void main(
String args[]){
ABC a = new XYZ();//line 1
XYZ x = new MNO();//line 2
a = new MNO();//line 3
x = new ABC();//line 4
}
}
class ABC{
int i;
}
class XYZ extends ABC{
int j;
}
class MNO extends XYZ{
int k;
}
Here ABC is parent class so it can hold object of child XYZ.
on line 4 it will throw following error:
"Incompatible type for =. Explicit cast needed to convert ABC to XYZ."
Since MNO is also sub class of ABC line 3 is correct.