How compiler decide parent class'method or child class's method to call? What is the meaning of this: Parent obj=new child_obj;
A super class reference variable can refer to a subclass object.When an overridden method is called through a super class reference ,Java determines which version of that method to execute based upon the type of object being referred at the time call occurs.Thus,this determination is made at the run time.
So, Parent obj=new child_obj; means obj is reference of type Parent class which referred to child class.So,when we call a method using this reference variable then child class's method will be called.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.