您现在的位置是:首页 > 电脑 > 

Java中的默认构造函数(Default ctructors in Java)

2025-07-17 01:52:56
Java中的默认构造函数(Default ctructors in Java) 我知道我在这里问一些严重的101个问题 我有一些类Foo和一个扩展Foo的类Bar 。 在Foo我有一个构造函数,它将一组参数设置为其字段。 派生类(例如Bar通常不需要修改这个。 现在我的IDE给了我“Foo中没有默认的构造函数” 。 来自谷歌的一些这似乎是因为“构造函
Java中的默认构造函数(Default ctructors in Java)

我知道我在这里问一些严重的101个问题

我有一些类Foo和一个扩展Foo的类Bar 。 在Foo我有一个构造函数,它将一组参数设置为其字段。 派生类(例如Bar通常不需要修改这个。 现在我的IDE给了我“Foo中没有默认的构造函数” 。 来自谷歌的一些这似乎是因为“构造函数不被继承”。 所以很好,很好,但是如何在每个派生类中重复这个构造函数呢? 我假设有一个更健全的方法?

I know I'm asking some serious 101 question here...

I have some class Foo and a class Bar that extends Foo. In Foo I have a ctructor that takes a set of parameters that it sets to its fields. Deriving classes such as Bar will typically not need to modify this. ow my IDE is giving me "There is no default ctructor available in Foo". From a bit of Googling this appears to be because "ctructors are not inherited". So all nice and well, but how do I now get this to work without duplicating this ctructor in every deriving class? I'm assuming there is a more sane approach?

最满意答案

使用super构造函数:

public Bar(int a, double b, ...) { super(a, b, ...); }

Use the super ctructor:

public Bar(int a, double b, ...) { super(a, b, ...); }

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/79494.html

相关标签:无
上传时间: 2023-04-28 04:54:22
留言与评论(共有 14 条评论)
本站网友 临江二手房
14分钟前 发表
b
本站网友 夺命金
28分钟前 发表
它将一组参数设置为其字段
本站网友 菠萝上火还是下火
9分钟前 发表
double b
本站网友 炒黄豆的功效与作用
5分钟前 发表
double b
本站网友 医疗服务
7分钟前 发表
现在我的IDE给了我“Foo中没有默认的构造函数”
本站网友 t800
25分钟前 发表
double b
本站网友 口腔医学杂志
10分钟前 发表
double b
本站网友 财务顾问
22分钟前 发表
double b
本站网友 西药
21分钟前 发表
...) { super(a
本站网友 顺德楼市
11分钟前 发表
...); } Use the super ctructor
本站网友 石家庄租房网
30分钟前 发表
...) { super(a
本站网友 网页视频下载工具
21分钟前 发表
派生类(例如Bar通常不需要修改这个
本站网友 朱洪达
26分钟前 发表
b