day10-多态的格式与使用
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
package com.inmind.duotai08;
|
||||||
|
|
||||||
|
public class Assissant extends Employee{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void work() {
|
||||||
|
System.out.println("助教在帮助学生");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
package com.inmind.duotai08;
|
package com.inmind.duotai08;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
定义
|
定义
|
||||||
多态: 是指同一行为,具有多个不同表现形式。
|
多态: 是指同一行为,具有多个不同表现形式。
|
||||||
@@ -19,4 +20,16 @@ package com.inmind.duotai08;
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
public class Demo08 {
|
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();
|
||||||
|
//多态:是框架技术展示的核心!!!!
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.inmind.duotai08;
|
||||||
|
|
||||||
|
public class Employee {
|
||||||
|
String name;
|
||||||
|
int age;
|
||||||
|
double salary;
|
||||||
|
|
||||||
|
public void work(){
|
||||||
|
System.out.println("员工正在工作");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.inmind.duotai08;
|
||||||
|
|
||||||
|
public class Teacher extends Employee{
|
||||||
|
|
||||||
|
//对工作的功能,要更加细分
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void work() {
|
||||||
|
System.out.println("老师正在教课");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user