Interfaces

September 10th, 2006 Admin Posted in Interfaces No Comments »

Interfaces

Interfaces are similar to classes but they have all abstract methods.
It can be created using a keyword called interface. Using  interfaces Java supports multiple inheritance  indirectly.

Eg:

interface Colorable
{
public  abstract void  makeColorable( ) ;
}

Using interfaces

The interface can be used by the class by using keyword implements.

Example :  Shape is a class,  which has area().Circle is a subclass of Shape.  We want to make  Circle  as colorable.  The code can be given as follows :

class  Circle  extends   Shape  implements Colorable
{     ……     }

AddThis Social Bookmark Button