Issue
I write this one:
parent obj1=new Child();
Child obj2 =(Child)obj1; //downcasting
like this one:
Child obj2 = new Child(); //creating child object
Solution
There difference is that in one case you have two references to one object. In the other, you have two references pointing to two different objects. Consider how it works with the following:
parent.kill();
if (child.isDead()) {
System.out.println("He's dead");
} else {
System.out.println("He lives!");
}
If the references point to the same object then we will print out "He's dead". If they are pointing to two different objects then we will print out "He lives!".
Answered By - vsfDawg
Answer Checked By - Clifford M. (JavaFixing Volunteer)