[java] interface

This time I will describe the interface.

What is an interface?

For later implementing and using the method. For example, addition and subtraction can be combined with calculations. At this time, the calculation is the interface, and the addition and subtraction are the classes that implement the interface.

Program using the interface

The interface can be defined as follows.

 // interface Interface name {}
interface Calc{}

In the interface -Field: Only constants can be declared (implicitly qualified with public static final) -Method: Only abstract methods can be defined (implicitly qualified with public abstract) It has been decided.

interface Calc{
 int NUM1 = 1; // Qualifier omits public static final
    int NUM2 = 10;

 void calc (); // abstract method
}

The interface can be implemented using implements. If there is a class that adds by interface implementation, it is as follows.

 // class class name implements interface name {}
class Plus implements Calc{
    public void calc(){
        System.out.println( NUM1 + NUM2 );
    }
}

Summary

The interface is also involved in object-oriented design. This is an important idea in development, so please master it. that's all.

Recommended Posts

java (interface)
[java] interface
About Java interface
[Java] About interface
[Java] Functional interface
About interface, java interface
About Java functional interface
Callable Interface in Java
JAVA learning history interface
Java
Java learning memo (interface)
Java
Advanced inheritance abstract, interface -java
JAVA learning history interface inheritance
[Java] Functional interface / lambda expression
Check Java9 Interface private methods
Access the network interface in Java
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
java (override)
java (method)
Java Day 2018
Java string
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
[Java] compareTo
Studying Java -5
[Java beginner] About abstraction and interface
java reflexes
Java memorandum
☾ Java / Collection
new interface
Java array
[Java] Array
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
Java inheritance
[Java] Overload