定义没有任何抽象方法的抽象类 [英] Defining an abstract class without any abstract methods
本文介绍了定义没有任何抽象方法的抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在不添加抽象方法的情况下定义抽象类吗?
解决方案
b
声明一个类的抽象只意味着你不允许它自己实例化。
声明一个方法抽象意味着子类必须提供该方法的实现。
这两个是单独的概念,但显然你不能在非抽象类中有一个抽象方法。你甚至可以有 final
方法的抽象类,但从来没有其他方法。
Can I define an abstract class without adding an abstract method?
解决方案
Of course.
Declaring a class abstract only means that you don't allow it to be instantiated on its own.
Declaring a method abstract means that subclasses have to provide an implementation for that method.
The two are separate concepts, but obviously you can't have an abstract method in a non-abstract class. You can even have abstract classes with final
methods but never the other way around.
这篇关于定义没有任何抽象方法的抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文