在Java中为抽象类创建构造函数的用法是什么? [英] What is the use of creating a constructor for an abstract class in Java?

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

问题描述

我想知道抽象类的构造函数的用途;因为我们不实例化抽象类,为什么我们需要这样的构造函数?

I would like to know what purpose a constructor for an abstract class serves; as we do not instantiate abstract classes, why would we ever need such a constructor?

推荐答案

所有继承类都需要设置的实例变量的公共初始化。当你扩展一个抽象类时,你需要实例化一个抽象类,具体的类有一个构造函数,它将为抽象类的构造函数提供参数。

there will be times when you have some common initialization of instance variables that all the inheriting classes need to set up. You do instantiate an abstract class when you extend it and that concrete class has a constructor that will either supply the parameters to the constructor of the abstract class.

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

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