Interface
Interface
In other words, you can say that interfaces can have abstract methods and
variables. It cannot have a method body.
There are mainly three reasons to use interface. They are given below.
Syntax:
interface <interface_name>{
Nested Interface
• An interface i.e. declared within another interface or class is
known as nested interface. The nested interfaces are used to
group related interfaces so that they can be easy to maintain.
The nested interface must be referred by the outer interface or
class. It can't be accessed directly.
Points to remember for nested interfaces
• Nested interface must be public if it is declared inside the
interface but it can have any access modifier if declared within
the class.
• Nested interfaces are declared static implicitly.
interface A{
void m1();
interface B {
void m2();
}
}
class T implements A,A.B{
public void m1(){
System.out.println("this is m1 method");
}
public void m2(){
System.out.println("this is m2 method");
}
public static void main(String args[])
{
T t=new T();
t.m2();
t.m1();
}
}
Output:
This is m2 method
This is m1 method