107k views
1 vote
Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method: Measurable m = new BankAccount(); System.out.println(_________________________); Select the correct expression to display the balance of the bank account.

1 Answer

3 votes

Answer:

((BankAccount) m).getBalance()

Step-by-step explanation:

m.getBalance look like the most appropriate answer but if we take a look at the Measurable interface, we realized that getMeasure doesn't return a String. So, in other to avoid runtime exception, we try to cast the return type to object of BankAccount type.

The code snippet would be;

Measurable m = new BankAccount();

System.out.println(((BankAccount) m).getBalance());

User POV
by
5.5k points