interface Pet{ |
public void buy(Animal animal); |
public void Feed(Animal animal); |
} |
class Buy implements Pet |
{ |
public void buy(Animal animal) |
{ |
System.out.println( "buy" +animal.getName()); |
} |
@Override |
public void Feed(Animal animal) { |
// TODO Auto-generated method stub |
|
} |
} |
class Feed implements Pet |
{ |
public void Feed(Animal animal) |
{ |
System.out.println( "buy" +animal.getName()); |
} |
@Override |
public void buy(Animal animal) { |
// TODO Auto-generated method stub |
|
} |
} |
abstract class Animal |
{ |
protected String name; |
public String getName() { |
return name; |
} |
public void setName(String name) { |
this .name = name; |
} |
} |
class Cat extends Animal |
{ |
public Cat(String name) { |
this .name = name; |
} |
} |
class Boss |
{ |
public static void sell(Pet pet, Animal animal) |
{ |
pet.buy(animal); |
} |
} |
public class PetStore |
{ |
public static void main(String[] args) { |
Boss boss= new Boss(); |
Pet pet= new Buy(); |
Animal animal= new Cat( "mao" ); |
Boss.sell(pet,animal); |
|
} |
} |
初级程序员
by: 云代码会员 发表于:2018-06-27 09:08:58 顶(0) | 踩(0) 回复
111111
回复评论