public interface abc
{
static int i=0; void dd();
class a1
{
a1()
{
int j;
System.out.println("inside");
};
public static void main(String a1[])
{
System.out.println("in interfia");
}
}
}
A class is defined inside an interface to bind the interface to a TYPE.
A small but nonsense example:
interface employee{
class Role{
public String rollname;
public int Role id;
public Object person;
}
Role getRole();
// other methods
}
In the above interface you are binding the Role type strongly to the employee interface(employee.Role).
One more reason is to have modifiable data within an interface(As you may know all fields in an interface are implicitly final). By declaring a class inside the interface you can have common MODIFIABLE data.
public interface abc{
static int i=0; void dd();
class a1{
private int a1;
int getA1(){
return a1;
}
int setA1(int a){
a1 = a;
}
}
a1Instance a1Ins = new a1Instance();
}
Comments
Post a Comment