JAVA 多态的基本意思

 

package Demo513.Multi;

public class DemoMultiMethod {
public static void main(String[] args) {
//写法格式 父类名 对象名= new 子类名();

Employee one =new Teacher();
one.work();
Employee two =new Assistant();
two.work();
}
}
class Employee{
void work(){

}
}
class Teacher extends Employee{
@Override
void work(){
System.out.println("讲课");

}

}
class Assistant extends Employee{
@Override
void work(){
System.out.println("辅导");
}
}
运行代码↓

 

 
posted @ 2019-05-14 11:26  Ssinoo団子  阅读(281)  评论(0编辑  收藏  举报