Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi any body help me . regarding..
is compulsory to implement all the methods in interface? that i implement to my class? sorry for my poor english
thank you
Posted

Is is compulsory to ask questions like this one?

Each and every help page in interfaces will have an answer to this question.
However, one delicate moment is: if your implementing type is class and if this class is derived from some class where this interface is already implemented, you can re-implement only some of the interface members.

The ability to do this is one great benefit over C++ where implementing COM interfaces is some problem due to lack of this feature.

—SA
 
Share this answer
 
v2
Comments
Abhinav S 13-May-11 6:09am    
5 - very useful. I did not know about this extra condition.
Sergey Alexandrovich Kryukov 13-May-11 6:28am    
Thank you, Abhinav.
--SA
Wayne Gaylard 13-May-11 7:11am    
That's useful to know. Thanks.
Sergey Alexandrovich Kryukov 13-May-11 7:34am    
It is. Thank you, Wayne.
--SA
Yes. It is. You wont be able to compile your code without at least providing the method stub in your class.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-May-11 5:52am    
Strictly speaking, this is true, my 5, but... there is one moment...
please see my answer.
--SA
Yes, it is mandatory to implement all the methods in a class that implements an interface unless and until that class is an Abstract class.

Let's Make it Simple,

MSIL
You have two choices:

- implement every method required by the interface
or
- declare the missing methods abstract in your class. This forces you
to declare your class abstract and, as a result, forces you to
subclass the class (and implement the missing methods) before you
can create any objects.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-May-11 6:10am    
Correct, my 5, but you can also re-implement it without virtual.
--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