Does java support multiple dispatch? If not how is the below code working?
Account.java
public interface Account
{
public void calculateInterest();
}
SavingsAccount.java
public class SavingsAccount implements Account
{
}
LoanAccount.java
public class LoanAccount implements Account
{
}
InterestCalculation.java
public class InterestCalculation
{
public void getInterestRate(Account objAccount)
{
System.out.println("Interest Rate Calculation for Accounts");
}
public void getInterestRate(LoanAccount loanAccount)
{
System.out.println("Interest rate for Loan Account is 11.5%");
}
public void getInterestRate(SavingsAccount savingAccount)
{
System.out.println("Interest rate for Savings Account is 6.5%");
}
}
CalculateInterest.java
public class CalculateInterest
{
public static void main(String[] args)
{
InterestCalculation objIntCal = new InterestCalculation();
objIntCal.getInterestRate(new LoanAccount());
objIntCal.getInterestRate(new SavingsAccount());
}
}
Output
Interest rate for Loan Account is 11.5% Interest rate for Savings Account is 6.5%