class Test_Boss {
public static void main(String[] args) {
Teacher t = new Teacher("冯佳",28);
t.eat();
t.study();
Student s = new Student("小明",18);
s.eat();
s.study();
s.smoke();
}
}
abstract 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 abstract void eat();
public abstract void study();
}
interface Smoking {
public void smoke();
}
class Teacher extends Person {
public Teacher() {}
public Teacher(String name,int age) {
super(name,age);
}
public void eat() {
System.out.println("我的姓名是:" + this.getName() + ",我今年" + this.getAge() + "岁" + ",我在吃饭");
}
public void study() {
System.out.println("我的姓名是:" + this.getName() + ",我今年" + this.getAge() + "岁" + ",我在学习");
}
}
class Student extends Person implements Smoking{
public Student() {}
public Student(String name,int age) {
super(name,age);
}
public void eat() {
System.out.println("我的姓名是:" + this.getName() + ",我今年" + this.getAge() + "岁" + ",我在吃饭");
}
public void study() {
System.out.println("我的姓名是:" + this.getName() + ",我今年" + this.getAge() + "岁" + ",我在学习");
}
public void smoke() {
System.out.println("我的姓名是:" + this.getName() + ",我今年" + this.getAge() + "岁" + ",我在抽烟");
}
} |
|