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]); }}
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]); }}
解决方案 »
- 如何applet实现图形间自动连接
- 正则表达式
- 方法为什么不能这样调用
- Hibernate的分页问题
- 安装了不同版本的jdk(j2se)后就出现这个问题!真烦!
- 加分了。想用jmf写一个视频会议软件请大家给些写服务器端和客户端的架构建议,客户端想用applet
- 下载了一个Weblogic8,脱机下无法安装?怎么办??(我的机器没法上网)
- java 程序中如何调用用 c++ 写的程序?
- 按钮事件的问题(如输入帐号,密码问题):我要将同一个按钮按次数不同完成不同的事,但第二次判断用e.getActionCommand()就无效了.为什么
- 对象序列化--存储数据库的方法 序列化后 不能使用
- 关于ResultSetMetaData 自动获取表列和表值
- java实现数组去重的问题
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
The return type is incompatible with PersonManage.getOne(int) at StudentManage.getOne(TestStudentManage.java:63)
at TestStudentManage.main(TestStudentManage.java:83)
为什么我的eclipse能通过?