百合文库
首页 > 网文

java oop的题与答案代码(老师代码版):葫芦娃题,多态,extends,finals,数组

2023-04-26 来源:百合文库
版本一:
package T9_多态;//package 包名可以是中文
public class finals {
//这个PI是不能修改的,最终的意思
public static void main(String[] args) {
//葫芦娃类
moxing m1=new huluwa("大娃","力大无穷");
moxing m2=new huluwa("二娃","千里眼");
//人类
moxing ren1=new renlei1("爷爷","男");
moxing [] ms=new moxing[3];
ms[0]=m1;ms[1]=m2;ms[2]=ren1;
for(int i=0;i<ms.length;i ){
if(ms[i] instanceof huluwa){
ms[i].gongneng();
}else if(ms[i] instanceof renlei1){
ms[i].gongneng();
}
}
}
}
class moxing{
public String name;
public void gongneng()
猜你喜欢