gpt4 book ai didi

java - 为什么我们不能将实例变量传递给父类(super class)构造函数?

转载 作者:行者123 更新时间:2023-12-05 09:00:05 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Cannot refer to a instance method while explicitly invoking a constructor

我已经尝试了很长时间了。

public class bb extends test {

int t = 23;

public bb() {
super(t); //**This is the place that error comes**
// TODO Auto-generated constructor stub
}

public bb(int v) {
}
}

public class test {

public test() {
// TODO Auto-generated constructor stub
}

public test(int v) {
// TODO Auto-generated constructor stub
}
}

Controller 类

class s {   
public static void main(String[] args) {

bb sd = new bb();
System.out.println("sdfsdfsdfd");
}
}

这是来的错误。我想知道为什么不能将实例变量传递给父类(super class)构造函数?我怀疑这是因为构造函数没有可访问的实例。

线程“main”中的异常 java.lang.Error: Unresolved 编译问题: 显式调用构造函数时无法引用实例字段 t

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com