Click here to Skip to main content
15,887,985 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
We all know Interfaces are not classes and so interfaces do not inherit any class and even do not inherit object class.

But when we Implement a interface in a class and override the object class method in that class, then we can call that object class method overridden in our child class from the interface(by interface reference variable).

How can interface call personal methods of child class?

Answer Please..........
Posted
Updated 5-Jun-12 22:27pm
v2
Comments
AmitGajjar 6-Jun-12 5:57am    
didn't get your last line : "How can interface call personal methods of child class?" can you elaborate ?

when you say ImyInterface obj = new ImplementedClass(), obj is actually pointing to the reference of ImpletedCalss object instance on the heap and hence it is able to access the method on the object.
 
Share this answer
 
Comments
Mahesh Kumar Badgujar 5-Jun-12 7:24am    
But if we create our own method Let say "public void Show()" in child class.
In this case also the Interface Obj(reference) points to the reference of the child class object on heap.

Then why it says that interfaces can't call personal methods of it's child class.
Answering the follow-up question:

There is no such thing as "personal method". It can be called, via type cast. It cannot be called directly only because the run-time type is not known exactly, but it's known that it is of the type System.Object.

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 19-Jul-12 17:59pm    
That's right :-D
Sergey Alexandrovich Kryukov 19-Jul-12 23:55pm    
Thank you, Espen.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900