class Person{
private String id;
public Person(String id){
this.id=id;
}
public String getId(){
return id;
}
public String toString(){
return id+"";
}
}class Student extends Person{
private String stuId;
public Student(String id,String stuId){
super(id);
this.stuId=stuId;
}
public String getStuId(){
return stuId;
}
public String toString(){
return this.getId()+":"+stuId+" ";
}
}class PersonManage{
public Person[] infoList;
public PersonManage(){
infoList=new Person[3];
infoList[0]=new Person("111");
infoList[1]=new Person("222");
infoList[2]=new Person("333");
for(int i=0;i<infoList.length;i++){
System.out.println(infoList[i]);
}
}
public Person getOne(int index){
if(index>=0 && index<infoList.length){
return infoList[index];
}
else{
return null;
}
}
public String toString(){
return infoList[0].toString()+infoList[1].toString()+infoList[2].toString();
}
}class StudentManage extends PersonManage{
public Student[] infoList;
public StudentManage(){
infoList=new Student[3];
infoList[0]=new Student("111","999");
infoList[1]=new Student("222","888");
infoList[2]=new Student("333","777");
for(int i=0;i<infoList.length;i++){
System.out.println(infoList[i]);
}
}
public Student getOne(int index){
if(index>=0 && index<infoList.length){
return infoList[index];
}
else{
return null;
}
}
public String toString(){
return infoList[0].toString()+infoList[1].toString()+infoList[2].toString();
}
}
public class TestStudentManage { /**
 * @param args
 */
public static void main(String[] args) {
System.out.println("第一个调用!");
StudentManage stuMge=new StudentManage();
Student stu=stuMge.getOne(1);
System.out.println(stu.getId());
System.out.println(stu.getStuId());
System.out.println("用来与第二个调用对比的输出如下:");
System.out.println(stuMge.infoList[0]);
System.out.println("第二个调用!");
PersonManage personMge=new StudentManage();
System.out.println(personMge.infoList[0]); }}

解决方案 »

  1.   

    eclipse下,要新建TestStudentManage.java文件,而且不能放在包里。。
      

  2.   

    因为studentManage类继承于personManage嘛,后面有一个方法
    public Student getOne(int index){
    if(index>=0 && index<infoList.length){
    return infoList[index];
    }
    else{
    return null;
    }
    重写了前面的方法 public Person getOne(int index) ,这里Eclipse提示有问题应该将Person 改为Student
      

  3.   

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The return type is incompatible with PersonManage.getOne(int) at StudentManage.getOne(TestStudentManage.java:63)
    at TestStudentManage.main(TestStudentManage.java:83)
      

  4.   


    为什么我的eclipse能通过?