- class TestStudentInterface {
- public static void main(String[] args) {
- Person p = new Teacher();
- p.eat();
- SmokeStudent ss = new SmokeStudent();
- ss.eat();
- ss.study();
- ss.smoking();
- }
- }
- class Person {
- String name;
- int age;
- public Person() {}
- public Person(String name,int age) {
- this.name = name;
- this.age = age;
- }
- public void eat() {
- System.out.println("吃饭");
- }
- }
- class Student extends Person{
- public Student() {}
- public Student(String name,int age) {
- super();
- }
-
- public void study() {
- System.out.println("学习");
- }
- }
- class Teacher extends Person{
- public Teacher() {}
- public Teacher(String name,int age) {
- super();
- }
-
- public void teach() {
- System.out.println("教书");
- }
- }
- interface smoking {
- public void smoking();
- }
- class SmokeStudent extends Student implements smoking {
- public SmokeStudent() {}
- public SmokeStudent(String name,int age) {
- this.name = name;
- this.age = age;
- }
- public void smoking() {
- System.out.println("学生抽烟");
- }
- }
- class SmokeTeacher extends Student implements smoking {
- public SmokeTeacher() {}
- public SmokeTeacher(String name,int age) {
- this.name = name;
- this.age = age;
- }
- public void smoking() {
- System.out.println("教师抽烟");
- }
- }
复制代码 |
|