当前位置:网站首页>What is the difference between abstract classes and interfaces?

What is the difference between abstract classes and interfaces?

2022-07-23 11:57:00 shuo277

In terms of design , Abstraction is the abstraction of a class , Is a template design , Interface is the abstraction of behavior , It's a code of conduct .

  • Java Provides and supports the creation of abstract classes and interfaces . They have something in common , The difference is : All methods in the interface are implicit and abstract , Abstract classes can contain both abstract and non abstract methods .

  • Classes can implement many interfaces , But you can only inherit from one abstract class . Class does not implement all methods declared by abstract classes and interfaces , Of course , under these circumstances , Class must also be declared abstract .

  • Abstract classes can implement an interface without providing an interface method implementation .

  • Java The variables declared in the interface are all final Of . Abstract classes can contain non final The variable of .

  • Java The member functions in the interface are... By default public Of . The permission modifier of an abstract class member function can be private,protected Or is it public .

  • The interface is absolutely Abstract , Cannot be instantiated . Abstract classes cannot be instantiated either , however , If it contains #main(String[] args) Method can be called .

原网站

版权声明
本文为[shuo277]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230538517259.html