Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 72

Given:

class RateOfInterest {

public static void main (String[] args) {

int rateOfInterest = 0;

String accountType = "LOAN";

switch (accountType) {

case "RD";

rateOfInterest = 5;

break;

case "FD";

rateOfInterest = 10;

break;

default:

assert false: "No interest for this account"; //line n1

}

System.out.println ("Rate of interest:" + rateOfInterest);

}

}

and the command:

java ""ea RateOfInterest

What is the result?

    Correct Answer: B

    The given code contains an assertion statement with the default case of the switch, which is executed when none of the case matches. Since the accountType is set to 'LOAN', none of the cases in the switch match, causing the default case to be executed. With assertions enabled through the command 'java -ea RateOfInterest', an AssertionError is thrown with the message 'No interest for this account'. Therefore, the correct result is that an AssertionError is thrown.

Discussion
adnano1234Option: B

Exception in thread "main" java.lang.AssertionError: No interest for this account

samtash1034Option: B

B,test

shivkumarxOption: B

Answer is definitely B, the people who said A are not running the java with assertions enabled

asdfjhfgjuaDCVOption: B

B is the correct answer

steefaandOption: B

Assuming that "" is typo and it means - answer is B.

iSnoverOption: A

The answer is A, because the command in parentheses (java ""ea Rate Of Interest) does not enable assertions, but rather the command "java -ea RateOfInterest", if the command were typed correctly it would be letter B

tamanna786Option: A

Answer: A, tested