-6
class HouseHold extends Customer {

    public void requestCoupon() {
        Transaction();
        CouponCount = 20;
    }

    public double Transaction () {
        Payment += CouponPayment;
        return Payment;
    }
}


class GCustomer extends HouseHold { 

      public double Transaction () {
        Payment += DisCPayment;
        return Payment;
    }
}

I'm making an object (A) of the GCustomer class and I need to request coupon using the super class (A.requestCoupon();). What I'm stuck at is that the method requestCoupon() calls the Transaction() method and if A calls the request method will it call the one in super class or in base class?

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
RSkyler
  • 3
  • 2

2 Answers2

0

It will call from GCustomer class, once that the method Transaction() was overrided.

Brother
  • 2,150
  • 1
  • 20
  • 24
0

Polymorphism is enforced dynamically (at runtime) based on the actual type of the object that is calling the method. It relies on the ability to assign an object of a subclass to a reference of the superclass.

Also, notice that when you have an instance method in a class and you call another method inside that instance method without using an explicit reference (the reference.method() syntax), then the call is made through an implicit this reference which refers to the object actually making the call (in this case, the derived class).

malfunctioning
  • 435
  • 1
  • 3
  • 10