哪位大虾帮忙看看,实例抽象类出错!!!!!!!!不出输出结果

kobe_gino 2010-04-16 09:10:04
abstract class Person {
private String name;
private int age;

Person(String name,int age){
this.setName(name);
this.setAge(age);
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public abstract String tell() ;
}

class Student extends Person {
private String school;

public Student(String name,int age,String school) {
super(name,age);
this.setSchool(school);
}

public void setSchool(String school) {
this.school = school;
}

public String getSchool() {
return school;
}

public String tell() {
return "姓名:"+super.getName()+"年龄:"+super.getAge()+"学校:"+this.school ;
}
}


class Worker extends Person {
private float salary;

public Worker(String name ,int age ,float salary) {
super(name,age) ;
this.setSalary(salary);
}

public void setSalary(float salary) {
this.salary = salary;
}

public float getSalary() {
return salary;
}

public String tell() {
return "姓名:"+super.getName()+"年龄:"+super.getAge()+"工资:"+this.salary ;
}
}


public class TestAbstract {
public static void main(String args[]) {
Person stu = new Student("leech",30,"tsinghua");
Person wor = new Worker("huang",26,3654f);

stu.tell();
wor.tell();
}
}
...全文
57 3 打赏 收藏 转发到动态 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
davis_rly 2010-04-16
  • 打赏
  • 举报
回复
这段程序没有看见显示语句啊 就像上面说的 可以加上System.out.println(stu.tell());
System.out.println(wor.tell());
kobe_gino 2010-04-16
  • 打赏
  • 举报
回复
xie xie
MingLoveHui 2010-04-16
  • 打赏
  • 举报
回复
把最下边的 stu.tell();
wor.tell();
输出

System.out.println(stu.tell());
System.out.println(wor.tell());
相关推荐

62,566

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告