为什么不使用抽象方法使用抽象类? [英] Why use an abstract class without abstract methods?

查看:196
本文介绍了为什么不使用抽象方法使用抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个java,而我正处于Abstract的一部分。
我读了一个奇怪的部分,我有一个抽象类
,它不包含任何abstarct方法。

I am now studying a java and I'm at the part of Abstract. I read sorta strange part to me that there is an abstract class which does not include any abstarct method.

为什么他们会使用这种类?

Why do they use this kind of class?

推荐答案

防止实例化该类并仅将其用作基类。子类可以使用抽象类中定义的常规方法。

To prevent instantiation of that class and use it only as a base class. Child classes can use the general methods defined in the abstract class.

例如,创建 AbstractVehicle 的实例是没有意义的。但是所有车辆都可以重复使用常见的 registerMileage(int)方法。

For example it doesn't make sense to create an instance of AbstractVehicle. But All vehicles can reuse a common registerMileage(int) method.

这篇关于为什么不使用抽象方法使用抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆