Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Originally posted by agrah upadhyay:
class C {
String m1(int i) {
switch (i) {
case 0: return "A";
case 1: return "B";
case 2: return "C";
default:
assert false;
}
}
public static void main(String[] args) {
C c = new C();
for (int i = 0; i < 4; i++) {
System.out.print(c.m1(i));
}}}
Which statements are true?
a. With assertions enabled it prints ABC followed by an AssertionError message.
b. With assertions disabled it prints ABC followed by an AssertionError message.
c. Assertions should not be used within the default case of a switch statement.
d. In this code example a throw statement must be used in place of the assert statement.
e. Compile-time error
Answer : d,e
*********************************************************************8
As You Know assertions Are Not Activated by default.so if assertion is disabled,what will happen wen i doesn't match any of the case and reaches to default statement?--it will not return anything right?but Its return type is String(so it can either return Strind or throw ab error condition) so due to compatibility problem compile time error will be there........right?So It Must be Relplaced by throw AssertionError which is always enabled
now Think In This Very Manner for your 2nd problem
Right?
##########################################
Agrah
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|