gfysuperman
OBJIECT
2017-10-27 09:56

属性没有多态,那这个算多态吗

  • 多态

class ZiXingChe extends Car
{
ZiXingChe(boolean fuza){
this.fuza = fuza;

}

}

class FaLaLi extends Car
{
FaLaLi(boolean fuza){
this.fuza = fuza;

}
}
class Car
{
boolean fuza;

}

class XiuChe
{
public void xiuLi(Car car){

    if(car.fuza == true){
      System.out.println("这个车修不了");
    }else{
      System.out.println("这个车可以修");
    }
 }

}

class TestXiuCar
{
public static void main(String[] args)
{
XiuChe x = new XiuChe();
x.xiuLi(new FaLaLi(true));
x.xiuLi(new ZiXingChe(false));

}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答