简单JAVA程序 报错

[复制链接]
查看11 | 回复1 | 2011-6-14 16:55:57 | 显示全部楼层 |阅读模式
class Person {
        private String name;
        private String location;
        Person(String s) {
                this.name = s;
                location = "beijing";
        }
        Person(String name, String location) {
                this.name = name;
                this.location = location;
        }
        public String info() {
                return name + location;
        }
}
class Student extends Person{
        private String school;
        Student(String school) {//报错:未定义隐式构造函数 Person
                this.school = school;
        }
        public String info() {
                return super.info()+school;
        }
}
public class Text01 {
        public static void main(String[] args) {
                Person p1 = new Person("perter");
       
Student stu1=new Student("清华");
                System.out.println(p1.info());
                System.out.println(stu1.info());
        }
}

回复

使用道具 举报

千问 | 2011-6-14 16:55:57 | 显示全部楼层
在Person 定义一个无参构造函数...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行