需求一:
public class Pro {
public String name;
public int id;
public int income;
public Pro() {
}
public Pro(String name, int id,int income) {
this.name=name;
this.id=id;
this.income=income;
}
public void Work() {
System.out.println(this.name);
System.out.println(this.id);
System.out.println(this.income);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIncome() {
return income;
}
public void setIncome(int income) {
this.income = income;
}
}
//
public class Jingli extends Pro{
private int bonus;
public Jingli() {
}
public Jingli(String name, int id,int income,int bonus) {
this.name=name;
this.id=id;
this.income=income;
this.bonus=bonus;
}
public int getBonus() {
return bonus;
}
public void setBonus(int bonus) {
this.bonus = bonus;
}
public void Work() {
System.out.println(this.getName());
System.out.println(this.id);
System.out.println(this.income);
System.out.println(this.bonus);
}
}
//
public class T1 {
public static void main(String[] args) {
Pro r=new Pro("李四",121121,10000);
r.Work();
Jingli s=new Jingli("张三",120120,20000,5000);
s.Work();
}
}
需求二:
public class Teach {
public String name;
public int age;
public Teach() {
}
public Teach(String name,int age) {
this.name=name;
this.age=age;
}
public void XingWei() {
System.out.println(this.name+"需要吃饭");
}
public void Pross() {
System.out.println(this.name+"上课");
}
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 class Stud extends Teach{
public Stud() {
}
public Stud(String name, int age) {
this.name=name;
this.age=age;
}
public void Pross() {
System.out.println(this.name+"听课");
}
}
//
public class T1 {
public static void main(String[] args) {
Pro r=new Pro("李四",121121,10000);
r.Work();
Jingli s=new Jingli("张三",120120,20000,5000);
s.Work();
Teach r1=new Teach("张老师",30);
r1.XingWei();
r1.Pross();
Stud s1=new Stud("王同学",20);
s1.XingWei();
s1.Pross();
}
}
需求三:
public class Cat {
public String name;
public char fur;
public int leg;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getFur() {
return fur;
}
public void setFur(char fur) {
this.fur = fur;
}
public int getLeg() {
return leg;
}
public void setLeg(int leg) {
this.leg = leg;
}
public Cat() {
}
public Cat(String name,char fur,int leg) {
this.name=name;
this.fur=fur;
this.leg=leg;
}
public void XingWei() {
System.out.println(this.name+"需要吃饭");
}
public void Catchmouse() {
System.out.println(this.name+"在夜里抓老鼠");
}
}
//
public class Dog extends Cat {
public Dog() {
}
public Dog(String name,char fur,int leg) {
this.name=name;
this.fur=fur;
this.leg=leg;
}
public void Lookhome() {
System.out.println(this.name+"需要看家");
}
}