Chapter 6 Interfaces




Chapter 6  Interfaces
java does not support multiple inheritance that is classes in java cannot have more than one super class. For instance a definition like
class A extend B extend C
{
.....
.....
}
is not permitted in java.
However, the designers of java could not overlook the importance of multiple inheritance. java provides an alternate approach known as interface to support the concept of multiple inheritance. Although a java class cannot be a sub class of more than one super class, it can implement more than one interface.
interface :
An interface is basically a kind of class like class interface contain methods and variables but with a major difference. The difference is that interface define only abstract methods and final fields. This means that interface donot specify any code to implement these methods and data field contain only constants. The general form of interface is :
interface interfacename
{
static final type var_name=value;
return_type methodname1(parameter_list);
}
Example :
interface Item
{
static final int code=101;
static final string name="Fan";
void display();
}