Method overload in Java

Overloading methods

If two or more methods of a class have the same name but different parameter lists, one speaks of Overloaded of the methods. When one of the methods (by or another method) is called, it is clear which method is meant by the correspondence of the current parameters with the formal parameter list.

Here's another change to the class:

class account {. . . . private int balance; . . . . void processInpayment (int amount) {balance = balance + amount; } void processInpayment (int amount, int fee) {account balance = account balance + amount - fee; }}

Assume that two methods are used:

  • One for normal deposits that are free of charge.
  • One for other deposits that may be charged a fee.

The code above implements this requirement. Here is an example of the method using both methods:

class AccountTester {public static void main (String [] args) {Account bobsKonto = new Account ("999", "Bob", 100); bobsaccount.processing deposit (200); // instruction A bobsAccount.processingInpayment (200, 25); // statement B}}

QUESTION 12:

Which of the following statements is correct?

  1. Statement A calls the first method.
  2. Statement A calls the second method.
  3. Statement B calls the first method.
  4. Statement B calls the second method.