ITPub博客

首页 > > > java多态

java多态

作者:markriver 时间:2019-11-18 10:02:03 0 删除 编辑

package my;

interface Animal{

void shout();

}

public static void animalshout(Animal an) { //为什么这行的void通不过编译啊?

an.shout();

}

class Cat implements Animal{

public void shout() {

System.out.println("喵喵喵");

}

}

class Dog implements Animal{

public void shout() {

System.out.println("汪汪汪");

}

}

class yichang {

public static void main(String[] args) {

Animal an1=new Dog();

Animal an2=new Cat();

animalshout(an1);

animalshout(an2);

}

}

有大佬能告诉我一下问题在哪吗?

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/818/viewspace-3161284/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Service Mesh浅谈
请登录后发表评论 登录
全部评论

注册时间:2020-07-03

  • 博文量
    502
  • 访问量
    18501