次のコードで:
class Payment { }
class CashPayment extends Payment{ }
class Store{
public void acceptPayment (Payment p)
{System.out.println ("Store::Payment");}
}
class FastFoodStore extends Store {
public void acceptPayment (CashPayment c)
{System.out.println ("FastFoodStore::CashPayment");}
public void acceptPayment (Payment p)
{System.out.println ("FastFoodStore::Payment");}
}
//
public class Example {
public static void main(String [] args){
Store store1 = new Store();
FastFoodStore sandwitchPlace = new FastFoodStore ();
Store store2 = new FastFoodStore();
Payment p1 = new Payment();
CashPayment cp = new CashPayment();
Payment p2 = new CashPayment();
store1.acceptPayment (p1);
store1.acceptPayment (cp);
store1.acceptPayment (p2);
sandwitchPlace.acceptPayment (p1);
sandwitchPlace.acceptPayment (cp);
sandwitchPlace.acceptPayment (p2);
store2.acceptPayment (p1);
store2.acceptPayment (cp);
store2.acceptPayment (p2);
}
}
私が本当に理解していないのはその理由です
store2.acceptPayment (cp);
FastFoodStore :: Paymentは表示されますが、FastFoodStore :: CashPaymentは表示されませんか?store2は基本的に、実行時にFastFoodStoreのメソッドを呼び出し、CashPaymentタイプのパラメーターを渡します。その場合、FastFoodStore::CashPaymentが表示されます。誰か助けてもらえますか?