What is an interface
Interfaces are similar to abstract classes and are abstract concepts that are decorated with interface keywords. That has the abstract class why also have an interface, since all is abstract, want a not to be able to? In fact, the abstract class is an abstraction for a class of things, but for some of the features and functions that belong to some individuals, we need interfaces to augment them. For example: person is the abstract of different people, such as black, white, yellow, and so on, they all have names, age, color and other properties, will walk, will run, will eat, will sleep these functions, but for some stunts, such as some people do not have the characteristics of the ordinary, for example, will turn the hand 360 degrees, These special non-common things can be placed in the interface, the people who have this feature can achieve the interface to inherit abstract method similar purposes.
Member features in the interface
From the member variables in the interface, construct methods and member methods to summarize.
- member variable:
Member variable regardless of whether the definition type is displayed, ;
- constructor method:
interface no construction Method!!! This differs from the abstract class. How does the subclass that implements the interface initialize? Because subclass initialization calls super () by default;
class Student extends Object Span style= "color: #0000ff;" >implements interperson{ public Student () { (); }}
In fact, if all classes do not have a write-inheriting class, the default is extends object, which is the ancestor class, so super () here calls the parameterless constructor method in the object class.
- member Method:
this differs from an abstract class in that the method in the abstract class can be abstract, can have its own method, and can have non-public type methods.
In addition, because the member method is public-abstract by default, natural cannot exist with both final and static.
in summary, there is no default construction method in the interface, all member variables are public static final decorated, and all member methods are public abstract decorated.
Summary of "Java Fundamentals" Java interface