This time I will describe the 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.
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 );
}
}
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