diff --git a/day10/src/com/inmind/duotai08/Assissant.java b/day10/src/com/inmind/duotai08/Assissant.java new file mode 100644 index 0000000..3b86bcb --- /dev/null +++ b/day10/src/com/inmind/duotai08/Assissant.java @@ -0,0 +1,9 @@ +package com.inmind.duotai08; + +public class Assissant extends Employee{ + + @Override + public void work() { + System.out.println("助教在帮助学生"); + } +} diff --git a/day10/src/com/inmind/duotai08/Demo08.java b/day10/src/com/inmind/duotai08/Demo08.java index a33fb24..e415790 100644 --- a/day10/src/com/inmind/duotai08/Demo08.java +++ b/day10/src/com/inmind/duotai08/Demo08.java @@ -1,4 +1,5 @@ package com.inmind.duotai08; + /* 定义 多态: 是指同一行为,具有多个不同表现形式。 @@ -19,4 +20,16 @@ package com.inmind.duotai08; */ public class Demo08 { + public static void main(String[] args) { + /*Teacher teacher = new Teacher();//本类引用指向本类对象(普通的面向对象) + teacher.work();*/ + + //多态的语法:父类引用指向子类对象【格式体现】 + Employee e = new Teacher(); + e.work(); + Employee e1 = new Assissant(); + e1.work(); + //多态:是框架技术展示的核心!!!! + + } } diff --git a/day10/src/com/inmind/duotai08/Employee.java b/day10/src/com/inmind/duotai08/Employee.java new file mode 100644 index 0000000..d3f5b70 --- /dev/null +++ b/day10/src/com/inmind/duotai08/Employee.java @@ -0,0 +1,11 @@ +package com.inmind.duotai08; + +public class Employee { + String name; + int age; + double salary; + + public void work(){ + System.out.println("员工正在工作"); + } +} diff --git a/day10/src/com/inmind/duotai08/Teacher.java b/day10/src/com/inmind/duotai08/Teacher.java new file mode 100644 index 0000000..f3f162c --- /dev/null +++ b/day10/src/com/inmind/duotai08/Teacher.java @@ -0,0 +1,11 @@ +package com.inmind.duotai08; + +public class Teacher extends Employee{ + + //对工作的功能,要更加细分 + + @Override + public void work() { + System.out.println("老师正在教课"); + } +}