An interface is defined much like a class. This is the general form of an interface:
access interface name
{
return-type method-name1(parameter-list);
return-type method-name2(parameter-list);
type final-varname1=value;
type final-varname1=value;
}
// A simple program to describe interface
interface Drawobject
{
float P=3.14f;
public void Area(int x);
}
class Mcolor
{
void Setcolor(String col)
{
System.out.println("Color selected by you is "+ col);
}
}
class circle extends Mcolor implements Drawobject
{
public void Area(int r)
{
float res=P*r*r;
System.out.println("Area of circle with r "+ res);
}
}
class Testinterface
{
public static void main(String arg[])
{
circle obj=new circle();
obj.Setcolor("red");
obj.Area(5);
}
}
Output:

0 comments:
Post a Comment