Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can I able to Create a Constructor Inside my Interface Class ?
Posted

No, you cannot. Interface is only a contract, it cannot have any executable code.
 
Share this answer
 
No. (Personally I think it is a mistake that you can't specify constructor signatures in an interface ... it means that there is no general way to create an implementing class without knowing what the class is or making assumptions about available constructors.) One way round this is to specify an Initialize method.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Aug-11 3:12am    
There is something reasonable in your doubt. My 5. You see, I think you mean Initialize as a factory method, it will define a signature for creation of the instance. This work-around is still not perfect: when one implements this factory method, it will be implemented as an instance method, while a normal factory method would be a static one -- so, we have some redundancy, right? This is a minor, but a problem.

It would not be a theoretical problem to allow static methods in interfaces and/or constructors.
--SA
It might be helpful,

interface[^]
class[^]

:)
 
Share this answer
 

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