lauqasim 2016-01-20 11:46 采纳率: 0%
浏览 1775

java程序在eclipse运行下出错,但是在cmd可以正常运行,求大神!

源代码:
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 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;
}
}

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()+"location"+capital;
}

}

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());
}

}

错误:
Exception in thread "main" java.lang.NoSuchMethodError: Person.(Ljava/lang/String;)Vat TestTeacher.main(TestTeacher.java:55)

  • 写回答

8条回答 默认 最新

  • threenewbee 2016-01-20 11:50
    关注

    person构造函数前面加上public

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘