Abstract class
Concept: Class modified by the abstract keyword
Member characteristics:
Constructor method: yes
Member variables: no limit, both constants and variables
Members Method: No limit, it can be abstract or not
Relationship with class: Inheritance relationship
Subclass of abstract class: It can be abstract or concrete (all abstract methods must be implemented )
Tips: If there are abstract methods in a class, then the current class must be defined as an abstract class
A subclass of the abstract class:
Either implement all abstract methods and call it a normal class
Or continue to abstract
Abstract classes cannot be instantiated directly ---->>The only difference between abstract classes and ordinary classes is that they cannot create instance objects and allow abstract methods
You can use polymorphism Instantiation is instantiated by its normal subclass
Interface
Concept: Java provides the standard interface
Definition format: permission modifier interface interface name {}
Member characteristics:
Construction method: No
Member variables: can only be constants, the default modifier is public static final
Member methods: can only be abstract methods. The default modifier of the method is public abstract
Relationship with the class: implementation relationship, multiple implementations can be implemented in a single way, or multiple implementations
Implementation class of the interface: either implements all abstract methods and is called a normal class, or declares it as abstract Class
Implementation of interface: Interface cannot be instantiated directly, and objects can be created by its instantiated classes in a polymorphic manner
There is an inheritance relationship between interfaces, which can be single or multiple inheritance
The above is the detailed content of Abstract classes and interfaces. For more information, please follow other related articles on the PHP Chinese website!