Abstract class:
When some methods of the parent class are not deterministic, the abstract keyword can be used to decorate the side [abstraction method], and the class is also decorated with abstract, which becomes an abstraction class.
When you use the abstract keyword to decorate a class, this class is called an abstract class.
When you use the abstract keyword to modify a method, this method is an abstract method.
Abstract class Note:
Abstract methods cannot be instantiated in abstract classes, only in subclasses.
Abstract classes can have no abstract abstraction method.
Once a class contains an abstract method, the class must be declared as an abstract class.
Abstract methods cannot have principals.
Interface: (a special abstract class, all methods are an abstract method)
The interface is to give some methods that do not have content encapsulated together, to a class to use, and then according to the specific circumstances of these methods written.
--Syntax Definition:
Class name implements interface {
Method
Variable
}
A class to implement an interface that uses the Implements keyword
public class Test implements interfacetest{
}
Considerations for the interface:
--the interface cannot be instantiated
--Multiple unrelated classes can implement the same interface
--A class can implement multiple unrelated interfaces
--Similar to inheritance, there is polymorphism between interfaces and implementation classes
--the property in the interface defaults to public static final and can only be public static final
--the interface can only define methods that are not implemented, the default is public, and can only be public, the interface may inherit other interfaces and add new properties and methods
An interface is a more abstract class, and the method of an abstract class can have a method body, and all methods in an interface have no method body.
Java abstract classes, interfaces