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

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

问题描述

因为我们不能实例化一个抽象类,那么在抽象类中有什么是必要的。

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天全站免登陆