Tuesday, January 29, 2008

Why Class can only implements Interface ?

As per definition-

Interface is a kind of contract that a class must perform when it implements the interface.


Why interface can not implement interface ?

As we know that interface is a contract or in technical terms we only define methods;we do not implement them. When an interface extends an interface we are actually combining two contract that a class will perform. So if an interface implements an interface, it has to implement methods. This means contract vanishes,so is the virtue of interface !!


Why interface can not extend class ?

If an interface extends class, it will inherit class methods along with their implementation. But as per definition an interface can not contain method implementation.


Why class can not extends interface ?

When class A extends another class B, it inherits all the methods of class B. The class A can choose to override inherited methods or it can also choose to skip overriding.
If a class A extends Interface I, it will inherits all the methods of I, as per interface contracts class A has to override or implements all the methods. But this is against the meaning of "extending". So a class can not extend interface.

No comments: