这道JAVA题怎么做?
展开全部
/**
* 2016/11/25 08:04
*
* @author 3306 TODO Person类
*/
public class Person {
int age;//年龄
String name;//姓名
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getContent() {
return "I'm " + name + " , my age is: " + age;
}
public void say() {
System.out.println(getContent());
}
}
/**
* 2016/11/25 08:07
*
* @author 3306 TODO 学生类
*/
public class Student extends Person {
private String stuNum;//学号
public Student(String stuNum, String name, int age) {
super(name, age);
this.stuNum = stuNum;
}
public void say() {
System.out.println(getContent());
}
public String getContent() {
return "I'm student, my name is: " + name + " , my age is: " + age + " ,stuNum is: " + stuNum;
}
}
/**
* 2016/11/25 08:10
*
* @author 3306 TODO 工人类
*/
public class Worker extends Person {
private String employeeNum;//工号
public Worker(String employeeNum, String name, int age) {
super(name, age);
this.employeeNum = employeeNum;
}
public void say() {
System.out.println(getContent());
}
public String getContent() {
return "I'm a worker, my name is" + name + " , age is: " + age + " , No: " + employeeNum;
}
}
/**
* 2016/11/25 08:11
*
* @author 3306 TODO
*/
public class Test {
public static void main(String[] args) {
Person worker = new Worker("1234567", "3306", 50);//工人
Person student = new Student("12052010", "lmm", 20);//学生
saySomething(worker);
saySomething(student);
}
/**
* 调用say方法
*
* @param person Person子类对象
*/
private static void saySomething(Person person) {
person.say();
}
}
更多追问追答
追问
你是学JAVA专业的么?
追答
算是吧,程序猿 :)
如果答案符合您的标准,请采纳
如要修改,请留言
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询