Java – Interface

Interface in Java is a collection of methods that are not implemented and they have to be implemented. It acts as a form for methods. An interface should be stored in .java file, and should start with capital letter, like classes. It does not have constructors or method bodies, just method signatures and fields.

syntax:

public interface InterfaceNAme{
    field(s)
    method signature(s)
}
Java - Interface, <span>Java – Interface</span>, KandZ

Then you implement it. First add implement and interface name at the class signature:

Java - Interface, <span>Java – Interface</span>, KandZ

Now you can see a red line that reminds you that you have to implement its methods:

Class ‘Man’ must either be declared abstract or implement abstract method ‘eats()’ in ‘Actions’

Go with the cursor to this line and press Alt + Enter. Choose Implements methods. You will see a window with the methods you have to implement. Select them and click OK

Java - Interface, <span>Java – Interface</span>, KandZ

IntelliJ IDEA just added the two methods, and you have to implement them.

Java - Interface, <span>Java – Interface</span>, KandZ

THE END!!!

89000cookie-checkJava – InterfaceJava – Interface

Related posts

One Thought to “Java – Interface

Comments are closed.