用java建一个 老师类:讲师-->副教授-->教授 急求!!!
发布网友
发布时间:2024-09-28 03:53
我来回答
共1个回答
热心网友
时间:2024-09-29 05:44
class person{
private String name;
private int age;
private String xing;
public person(String name, int age, String xing) {
super();
this.name = name;
this.age = age;
this.xing = xing;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getXing() {
return xing;
}
public void setXing(String xing) {
this.xing = xing;
}
public void gongneng(){
}
}
class Jiangshi extends person{
public Jiangshi(String name, int age, String xing) {
super(name, age, xing);
// TODO Auto-generated constructor stub
}
public void gongneng(){
System.out.println("班主任");
System.out.println("讲课");
}
}
class Fujiaoshou extends person{
public Fujiaoshou(String name, int age, String xing) {
super(name, age, xing);
// TODO Auto-generated constructor stub
}
public void gongneng(){
System.out.println("带研究生");
System.out.println("讲课");
}
}
class Jiaoshou extends person{
public Jiaoshou(String name, int age, String xing) {
super(name, age, xing);
// TODO Auto-generated constructor stub
}
public void gongneng(){
System.out.println("带研究生,带博士");
System.out.println("讲课");
}
}
public class test {
public static void main(String[] args) {
Jiangshi p1=new Jiangshi("小红", 25, "女");
p1.gongneng();
Fujiaoshou p2=new Fujiaoshou("明明", 30, "男");
p2.gongneng();
Jiaoshou p3=new Jiaoshou("都敏俊", 65, "男");
p3.gongneng();
}
}
//希望对你有用
追问谢谢,辛苦了。不过得用继承啊。得用这个extends