Given the code fragment:
String valid = "true";
if (valid) System.out.println (“valid”);
else system.out.println ("not valid");
What is the result?
A.
Valid
B.
not valid
C.
Compilation fails
D.
An IllegalArgumentException is thrown at run time
Explanation:
In segment ‘if (valid)’ valid must be of type boolean, but it is a string.
This makes the compilation fail.
WTF?
{} missing after the if statement. That’s WTF.
In the if statement valid is not a boolean so compilation will fail
c