Submitted by c-admin on Tue, 05/28/2019 - 06:41
Consider the code shown below:
public class TestClass{
public static int switchTest(int k){
int j = 1;
switch(k){
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default : j++;
} return j + k;
} public static void main(String[] args){
System.out.println( switchTest(4) );
}
}
What will it print when compiled and run?
Select 1 option
A. 5
B. 6
C. 7
D. 8
E. 9
Submitted by c-admin on Tue, 05/28/2019 - 06:37
What will happen when the following program is compiled and run?
public class SM{
public String checkIt(String s){
if(s.length() == 0 || s == null){
return "EMPTY";
}
else return "NOT EMPTY";
}
public static void main(String[] args){
SM a = new SM();
a.checkIt(null);
}
}
Select 1 option
A. It will print EMPTY.
B. It will print NOT EMPTY.
C. It will throw NullPointerException.
D. It will print EMPTY if || is replaced with |.
Submitted by c-admin on Tue, 05/28/2019 - 06:34
Consider the following code snippet:
XXXX m ;
switch( m ){
case 32 : System.out.println("32"); break;
case 64 : System.out.println("64"); break;
case 128 : System.out.println("128"); break;
}
What type can 'm' be of so that the above code compiles and runs as expected ?
Select 3 options
A. int m;
B. long m;
C. char m;
D. byte m;
E. short m;
Submitted by c-admin on Tue, 05/28/2019 - 06:27
What letters will be printed by this program?
public class ForSwitch{
public static void main(String args[]){
char i;
LOOP: for (i=0;i<5;i++){
switch(i++){
case '0': System.out.println("A");
case 1: System.out.println("B"); break LOOP;
case 2: System.out.println("C"); break;
case 3: System.out.println("D"); break;
case 4: System.out.println("E");
case 'E' : System.out.println("F");
}
}
}
}
Select 2 options
A. A
B. B
C. C
D. D
E. F
Submitted by c-admin on Tue, 05/28/2019 - 06:23
What will be the result of attempting to compile and run the following class?
public class IfTest{
public static void main(String args[]){
if (true)
if (false)
System.out.println("True False");
else
System.out.println("True True");
}
}
Select 1 option
A. The code will fail to compile because the syntax of the if statement is not correct.
B. The code will fail to compile because the values in the condition bracket are invalid.
C. The code will compile correctly and will not display anything.
D. The code will compile correctly and will display True True.
E. The code will compile correctly but will display True False
Pages