class demo_jiCheng {
public static void main(String[] args) {
Manager a = new Manager("沈经兵","sb123",25000,10000);
System.out.println(a.getName() + "..." + a.getId() + "..." + a.getSalary() + "..." + a.getJj());
a.work();
System.out.println("-----------------");
Coder b = new Coder("梅哲仁","sd234",15000);
System.out.println(b.getName() + "..." + b.getId() + "..." + b.getSalary());
b.work();
}
}
class Employee {
private String name;
private String id;
private int salary;
public Employee() {}
public Employee(String name,String id,int salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setSalary(int salary) {
this.salary = salary;
}
public int getSalary() {
return salary;
}
public void work() {
System.out.println("工作");
}
}
class Manager extends Employee{
private int jj;
public Manager() {}
public Manager(String name,String id,int salary,int jj) {
super(name,id,salary);
this.jj = jj;
}
public void setJj(int jj) {
this.jj = jj;
}
public int getJj() {
return jj;
}
}
class Coder extends Employee {
public Coder() {}
public Coder(String name,String id,int salary) {
super(name,id,salary);
}
}
要求二
class demo_Student {
public static void main(String[] args) {
Teacher c = new Teacher("老湿",25);
System.out.println(c.getName() + "..." + c.getAge());
c.eat();
c.teach();
Student d = new Student("小猫",13);
System.out.println(d.getName() + "..." + d.getAge());
d.eat();
d.study();
}
}
class Person {
private String name;
private int age;
public Person() {}
public Person(String name,int age) {
this.name = name;
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void eat() {
System.out.println("吃饭");
}
}
class Teacher extends Person {
public Teacher() {}
public Teacher(String name,int age) {
super(name,age);
}
public void teach() {
System.out.println("教书");
}
}
class Student extends Person {
public Student() {}
public Student(String name,int age) {
super(name,age);
}
public void study() {
System.out.println("学习");
}
}
要求三
class demo_ji {
public static void main(String[] args) {
Cat a = new Cat("花",4);
System.out.println(a.getColor() + "..." + a.getLeg());
a.eat();
a.catchMouse();
Dog b = new Dog("黑",4);
System.out.println(b.getColor() + "..." + b.getLeg());
b.eat();
b.dogLookHome();
}
}
class Animal {
private String color;
private int leg;
public Animal() {}
public Animal(String color,int leg) {
this.color = color;
this.leg = leg;
}
public void setColor(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public void setLeg(int leg) {
this.leg = leg;
}
public int getLeg() {
return leg;
}
public void eat() {
System.out.println("吃饭");
}
}
class Cat extends Animal {
public Cat() {}
public Cat(String color,int leg) {
super(color,leg);
}
public void catchMouse() {
System.out.println("抓老鼠");
}
}
class Dog extends Animal {
public Dog() {}
public Dog(String color,int leg) {
super(color,leg);
}
public void eat() {
System.out.println( "吃骨头");
}
public void dogLookHome() {
System.out.println("看家");
}
}
|
|