public class Main {
public static void main(String[] args) {
Student s = new Student("Xiao Ming", 12, 89);
}
}
class Person {
protected String name;
protected int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
class Student extends Person {
protected int score;
public Student(String name, int age, int score) {
super(name, age); // 调用父类的构造方法Person(String, int)
this.score = score;
}
}
六扇门捕快_
不是,这段代码,真的不会报错吗。。。
错误: 无法从静态上下文中引用非静态 变量 this
Student s = new Student("Xiao Ming", 12, 89);
要改成这样吧
static class Person{}
static class Student extends Person{}