请输入您要查询的百科知识:

 

词条 多态的例子
释义

//基类

public class Accpteacher {

private String name;

private String school;

public Accpteacher(String myName,String mySchool){

name=myName;

school=mySchool;

}

public void giveLesson(){

System.out.println("知识点讲解");

System.out.println("总结提问");

}

public void introduction(){

System.out.println("大家好!我是"+school+"的"+name+".");

}

}

//派生类

public class Java extends Accpteacher {

public Java(String myName,String mySchool){

super(myName,mySchool);

}

public void giveLesson(){

System.out.println("打开eclipse");

super.giveLesson();

}

}

//测试类

public class A {

public void judge(Accpteacher t){

t.introduction();

t.giveLesson();

}

public static void main(String args[]){

A a=new A();

Accpteacher as=new Java("无名氏","wuhan");

a.judge(as);

}

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/12/23 18:55:09