The interface is a fully unimplemented class in Java. The interface declared with the keyword interface. All methods present in an interface are abstract methods. Interface tell that what to implement, not how. The main objective of the interface is to achieve abstraction and multiple inheritances.
In Java, multiple inheritances are possible through interface only.
Any class implements the interface that should implement all the methods.
In Java, multiple inheritances are possible through interface only.
Any class implements the interface that should implement all the methods.
How to create an interface in Java
interface <INTERFACE_NAME> {// variable 1
// variable 2
// method 1 {}
//method 2 {}
}
Java Interface Example
interface demoInterface { void fun(); }
class Test implements demoInterface {
public void fun() {
System.out.println("Hello....");
}
public static void main(String args[]) {
Test obj = new Test();
obj.fun();
}
}
0 Comments