The difference between an abstract class and an interface
Abstract class
The class that contains the abstract method is the abstract class, the declared statement: abstract class
Must be public protected
Interface
An abstraction of behavior, declaring statements: interface
Modifiers for abstract methods: Public abstract
Modifiers for member variables: public static final
Grammatical level
- Abstract classes can contain implementation details for member methods, and only abstract methods exist in interfaces-public abstract
- The member variables in an abstract class can be of various types, and the member variables in the interface can only be public static final
- An abstract class can contain static methods and static code blocks that cannot be included in an interface
- A class can inherit only one abstract class and implement multiple interfaces
- Different access modifiers: the modifiers of the abstract class method are public/protected; The modifiers of the method in the interface must be public
Design level
Abstract classes are abstractions of things, abstractions of classes; interfaces are abstractions of behavior, describing a code of conduct
An abstract class is an abstract description of an entire class, containing attributes and behavior; an interface can only abstract the behavior of a class
Attach a Picture:
Thank you for reading, I hope to help you, thank you for your support for this site!