A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张甲甲 中级黑马   /  2013-5-16 23:24  /  973 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 张甲甲 于 2013-5-24 13:32 编辑

我写了一段代码 怎么编译就是不过 求大神指点啊
代码错误信息见插图

class Person{
  private String name;
  private String location;
  Person(String name) {
     this.name = name ;
     location  = "beijing";
  }
  Person(String name, String location) {
this.name = name;
this.location = location;
  }
  public String info() {
return
   "name:"+name+"location:"+location;
  }
}

class Teacher extends Person {
private  String   capital;
Teacher(String name, String capital) {

this(name,"beijing",capital);   
}

Teacher (String n, String l, String capital) {
  super(n,l);
this.capital = capital;

}
public String info () {

    return super.info() +  "capital"+capital;
}


}





class Student extends Person {
private String school;
Student(String name,String school) {
this(name,"beijing",school);
}
Student(String n,String l,String school) {
super(n,l);
this.school =  school;

}

  public String info () {

return super.info () + "school;"+school;

}
}

public class TestTeacher {
    public static void main (String [] args) {
    Person P1 = new Person ("A");
Person P2 = new Person ("B","shanghai");
Student S1 = new Student ("C","S1");
Student S2 = new Student  ("C","shanghai","S2");
System.out.println(P1.info());
System.out.println(P2.info());
System.out.println(S1.info());
System.out.println(S2.info());

Teacher t1 = new Teacher ("D", "professor");
System.out.println(t1.info());
    }
}

a.png (17.76 KB, 下载次数: 0)

a.png

评分

参与人数 1技术分 +1 收起 理由
袁梦希 + 1

查看全部评分

1 个回复

倒序浏览
代码可以运行,你换个文件夹存储文件,重新编译下试试。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马