Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling parent class method using child class object

 
Yash Don
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. Inside class Child you can call super.m1(), but what you want isn't possible.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but in case of overridden methods you cannot do that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic