| Author |
calling parent class method using child class object
|
Yash Don
Greenhorn
Joined: May 19, 2010
Posts: 12
|
|
Hi,
In one of the interview it was asked to me that how will you call parent class version of method using child class object?
The exact Scenario is given below...
Can you please tell me how can call Parent version of m1 method using an object of Child class...
Thanks,
Yash
|
Regards,
Yash
SCJP, SCWCD
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You can't. Inside class Child you can call super.m1(), but what you want isn't possible.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
here i have changed a little bit of code.....see it
here object is of type child1,and refernce is of type parent1.
but this is the case of overloaded method...in this refernce type determines which method to invoke not a object type....
i think interviewer ask a tricky question
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
|
but in case of overridden methods you cannot do that.
|
 |
 |
|
|
subject: calling parent class method using child class object
|
|
|