Java interface and abstract class small notes
@author Ixenos
Interface
1. The interface does not have a constructor because the interface is not instantiated
2. Anonymous objects if the constructor that uses the interface also simply represents a covariant anonymous object that implements the interface
3. The member variables in the interface are the public static final type by default. The initialization that must be displayed.
4. The method in the interface is the public abstract type by default. An implicit declaration.
5. The interface cannot implement another interface, but it can inherit multiple interfaces.
6. If a class implements an interface, then all the abstract methods inside the interface must be implemented
Abstract class
1. If in the parent class (here is your abstract class) The constructor that is written and parameterized is displayed in the subclass, you must write a constructor to invoke the child class inheritance.
The constructor of the parent class
Example:
1 Abstract classperson {//defines an abstract class that must be inherited2Person (inti) {3 }4 }5 6 Public classStudentextendsPerson {7 Student () {8 Super(inti)://the calling parent class constructor method must be displayed//Super Represents the parent class object9 }Ten}
2. If there are no arguments in the parent class constructor, in the subclass can not display the constructor of the write parent class, Java will automatically call the constructor without parameters
Example:
1 Abstract classperson {//defines an abstract class that must be inherited2Person () {//This constructor can also be non-writable, and Java will add a constructor without parameters by default3 }4 }5 6 Public classStudentextendsPerson {7 //constructor Function8 Student () {9 //super ();//can not write, Java will call this super () method itselfTen } One}
Java interface and abstract class small notes