抽象类中的构造函数有什么用? [英] What use are constructors in abstract classes?

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

问题描述

既然我们不能实例化抽象类,那么抽象类中有构造函数的必要性是什么?

Since we can't instantiate an abstract class, then what is the necessity of having constructors in abstract class?

推荐答案

抽象类旨在扩展,每个构造函数都来自子必须从基类调用构造函数,因此您需要在抽象类中使用构造函数.

Abstract classes are designed to be extended, each constructor from the child must perform a call to a constructor from the base class, thus you need constructors in your abstract class.

抽象类是一个骨架,因此直接实例化它没有意义,因为它仍然不完整(孩子们会提供其余的).

The abstract class is a skeleton and thus makes no sense to instantiate it directly since it is still incomplete (children will provide the rest).

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

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