public class Person {
String name;
public void p(){
System.out.println("The person's name is Zhangheng");
}
public static void main() {
Person per = new Person("Zhangheng");
per.p();
Student stu = new Student("Zhangyu");
stu.study();
}
}
class Student extends Person {
Student() {
super("Zhangyu");
}
public void study() {
System.out.println("The student is Studying");
}
}
错误在哪呢,是不是少写语句了。
题目:编写学生类,继承人类,要求父类的构造函数为(preson(string name),子类的构造函数要调用父类的构造函数.p()方法用于输出该对象的信息(如The person's name is Zhangheng),学生类有study()方法,并分别创建一个对象并调用各个方法 |