Friday, September 11, 2020

Interface In JAVA

                    Interface In JAVA



Interface:

An interface in Java is a blueprint of a class. It has static constants and abstract methods.

The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in java

It cannot be instantiated just like the abstract class.

In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body.



interface interf{

public void m1();
public void m2();
}

class test implements interf
{
public void m1(){

}                             

public void m2(){           

}
}

**** class should give implementation for all methods in interface and they have same access specifier.

****   if you not implemented all methods declare class as abstract .