JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
51 / 64
Choose the correct option.
String valid = "true";
if(valid)
System.out.println("valid");
else
System.out.println("not valid");
String valid = "true";
if(valid)
System.out.println("valid");
else
System.out.println("not valid");
Avalid
Bnot valid
CCompilation fails
DAn illegal argument exception thrown at runtime
Answer: Option (Login/Signup)
Show Explanation
Hence, we get an error saying, incompatible types : String cannot be converted to Boolean.
Asked In ::
STEP-BY-STEP
We get an error in this case, because valid is of String type, and in the if part we are actually comparing a String object with a Boolean value, which is not possible.
Hence, we get an error saying, incompatible types : String cannot be converted to Boolean.
Read Full Answer
Report Error
Please Login First Click Here