View RSS Feed

My Java Tips

An interface extending an interface

Rate this Entry
by , 11-20-2011 at 06:37 PM (1122 Views)
The subject topic is very interesting and I decided to write something on it. I hope it will be useful.


You know about the interfaces. They do not contain the implementation details, rather they contain the method signatures. The class implementing an interface, has to provide the implementation for each interface method. An interface in implemented using the keyword implements.


Java Code:
Class Room implements IOffice
{
The keyword extends is used for inheritance (re usability) and interfaces are not extended. For example, I tried to extend an interface and lets see what message I got:

Java Code:
public class Room extends IOffice {

}
Error:


The type IOffice cannot be a super class of Room; a superclass must be a class

So its clear not that interfaces are implemented and now extended.



Can an interface extend an interface? What sense this make?

Yes, interface can extend an interface and this would means reusing the extended interface. Simply stating, the whole extended interface will be part of the interface that is extending the other.

Lets do this:

Java Code:
public inerrface IInterface1 extends IInterface{
This actually means, IInterface is part of IInterface1.

You may also extend from more than one interface.

Java Code:
public inerrface IInterface1 extends IInterface,IInterface2{
This provides reusability

Submit "An interface extending an interface" to Facebook Submit "An interface extending an interface" to Digg Submit "An interface extending an interface" to del.icio.us Submit "An interface extending an interface" to StumbleUpon Submit "An interface extending an interface" to Google

Comments