使用没有任何抽象方法的抽象类 [英] Use of an abstract class without any abstract methods

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

问题描述

抽象类不需要包含任何抽象方法。

An abstract class need not include any abstract methods.

除了抽象类无法实例化之外,是否还有其他原因使类抽象化?

Is there any other reason to make a class abstract other than the fact that abstract classes can't be instantiated?

推荐答案

抽象类的主要作用是提供一个合适的根类,具体来说,(即非抽象的)可以派生子类。这是一个功能强大且功能多样的功能,可以促进代码重用。抽象类封装了一系列数据类型通用的一般特性 - 这些特性在抽象类中过于笼统而无意义,但可以在子类中重写

The principal role of an abstract class is to provide an appropriate root class from which concrete, (i.e. non-abstract) subclasses can be derived. This is a powerful and versatile feature which promotes code re-use. Abstract classes encapsulate general features that are common to a range of data types - features which are too general to be meaningful in the abstract class, but which can be overridden in a subclass

任何带抽象方法的类本身都是自动抽象的,必须用关键字abstract定义自己 - 有趣的是,抽象类不需要包含任何抽象方法

Any class with an abstract method is automatically abstract itself and must define itself as such with the keyword abstract - interestingly, an abstract class need not contain any abstract methods

摘要class无法实例化 - 换句话说,你不能创建抽象类的实例(对象)

An abstract class cannot be instantiated - in other words you cannot create instances (objects) of an abstract class

即使抽象类的对象,也可以声明对抽象类对象的引用无法实例化,例如Account a;将不会生成语法错误

References to objects of an abstract class can be declared even though objects of abstract classes cannot be instantiated, e.g Account a ; will not generate a syntax error

如果抽象类的子类重写,即在其超类中提供每个抽象方法的实现,则子类称为具体类,可以创建子类的对象

If a subclass of an abstract class overrides, i.e. provides an implementation of every abstract method in its superclass, the subclass is called a concrete class and objects of the subclass can be created

如果抽象类的子类没有覆盖(实现)它继承的所有抽象方法,那么子类本身也是抽象的必须声明为

If a subclass of an abstract class does not override (implement) all of the abstract methods it inherits, that subclass itself is also abstract and must be declared as such

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

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