Test Series - java

Test Number 31/64

Q: The condition of an IF statement evaluates to boolean only if the expression contains?
A. logical operators
B. relational operators
C. boolean operands
D. All
Solution: NO SOLUTION
Q: If the condition of an IF-statement is false, which is true below.
A. IF block is executed.
B. ELSE block is executed.
C. Both IF and ELSE blocks are skipped.
D. Both IF and ELSE blocks are executed.
Solution: If the condition is TRUE, IF-block is executed. Otherwise, ELSE-block is executed.
Q: What is maximum lines of code that can be written inside a Java style IF, ELSE or IF-ELSE block?
A. 32
B. 64
C. 512
D. None
Solution: There is no such limit on the number of lines of code in any block or statement in Java.
Q: An IF-ELSE statement is better than a SWITCH statement in which scenario below?
A. Checking for More-than condition
B. Checking for Less-than condition
C. Checking for Ranges
D. All
Solution: if(a>10 && a<20) { }
Q: What is the maximum number of ELSE-IF statements that can present in between starting IF and ending ELSE statements?
A. 32
B. 64
C. 128
D. None
Solution: You can write any number of ELSE-IF statements in a Java program.
Q: Choose the correct syntax of Java IF statement below.
A. if(condition) //statement
B. if(condition) { //statement }
C. if(condition) { //statement1 //statement2 }
D. All
Solution: NO SOLUTION
Q: Choose a wrong statement on Java IF-ELSE syntax below.
A. if(condition) //statement1 else //statement2
B. else //statement2
C. if(condition1) //statement1 else if(condition2) //statement2
D. if(condition1) //statement1 else if(condition2) //statement2 else //statement3
Solution: "ELSE" and "ELSE IF " statements should always be preceded by a valid IF statement.
Q: What is the output of Java program with IF statement?
if(1)
{
  System.out.println("OK");
}
A. OK
B. No output
C. Compiler error
D. None
Solution: The condition inside an IF statement should evaluate to either true/false. The below error is triggered.


Type mismatch: cannot convert from int to boolean
Q: What is the output of the Java program with IF-ELSE statements?
if(TRUE)
  System.out.println("GO");
else
  System.out.println("STOP");
A. GO
B. STOP
C. Compiler error
D. None
Solution: Error: TRUE cannot be resolved to a variable
Q: What is the output of the Java program?
int a=10;
if(a==9)
  System.out.println("OK ");
  System.out.println("MASTER");					
else
  System.out.println("BYE");
A. OK MASTER
B. BYE
C. Compiler error
D. None
Solution: More than 1 statement must be kept within Braces { } if ELSE or ELSE IF is next to the IF statement.


if(a==9)
{  
  System.out.println("OK ");
  System.out.println("MASTER");
}				
else
  System.out.println("BYE");

You Have Score    /10