Interface in Java

 

Java cannot support multiple Inheritance means we cannot create multiple super classes or we can say parents classes or base classes .This is the main reason we can create interface. In interface we can declare function only but not create the body.

 

 

Interface ss //interface declaration same as class declaration

{

public void f1(); //function definition only

}                 //interface closed

class dd implements ss //class inherits interface

{

public void f1()   //function declaration

{                     //f1 function body start

int a,b;

a=3;

b=5;

if(a>b)

{

System.out.println(“a is greater”);

}

Else

{

System.out.println(”b is greater”);

}

} //f1 function body closed(statement end)

}   //class dd closed

Class main

{

public static void main(String see[])

{

dd ob1=new dd();

ob1.f1();

}

}

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @