????????????????????????????????????????????????
??????????????淶?????????????????????
???????????????????????????????г???????????????????????????????????
????public interface PetRestaurant {
????public void buy();
????}
????????????????????????????????????????????
????public class DogPet implements PetRestaurant {
????@Override
????public void buy() {
????System.out.println("??????????????");
????}
????}
????????è??????????????????????????????????
????public class CatPet implements PetRestaurant {
????@Override
????public void buy() {
????System.out.println("????è???????è??");
????}
????}
??????????è?????????????????????????????????????????????????????????è????????????????????????????? ??????????????????????????????????????????????С???????????????????????????????????????????PetRestaurant ??????????????PetRestaurant ????
????public class test {
????public void buy(PetRestaurant pet)
????{
????pet.buy();
????}
????}
????????????????????????????????????????????????????????
????public class Tests {
????public static void main(String[] args) {
????PetRestaurant dog = new DogPet(); //??????????????????????????
????PetRestaurant cat = new CatPet();//????????è???????è????????
????test t = new test(); //??????????С??
????t.buy(cat); //??è??????С??
????t.buy(dog); //?????????С??
????}
????}
???????????е?????
????????è???????è??
??????????????????
?????????????????????????????????????????????????è??????????????????????????С????????Щ?????????????????????С??????С???????????????????Щ????è???????????????????????????С???????????????????????????????????????????????????????С???????????????????????????????С??????OK??????????С????????????仯???????????????????????????????OK
??????????????н???????????????è?????????????è??????????????????????????????????????????????????????С?????????????鷳