Submitted by c-admin on Tue, 05/28/2019 - 05:36
Which of the following four constructs are valid?
1.switch(5)
{
default :
}
2.switch(5)
{
default : break;
}
3.switch(8);
4.int x = 0;
switch(x){
}
Select 1 option
A. 1, 3
B. 1, 2, 3
C. 3, 4
D. 1, 2, 4
E. All are valid.
Submitted by c-admin on Tue, 05/28/2019 - 05:32
Consider that str is a variable of class java.lang.String.
Which of the following lines of code may throw a NullPointerException in certain situations?
Or a tougher version of the question could be :
Which of the following lines of code are not an example of robust design?
Select 3 options
A. if ( (str != null) | ( i == str.length() ) )
B. if ( (str == null) | ( i == str.length() ) )
C. if ( (str != null) || (i == str.length() ) )
D. if ( (str == null) || (i == str.length() ) )
Submitted by c-admin on Tue, 05/28/2019 - 05:23
Consider the following method...
public static void ifTest(boolean flag){
if (flag) //1
if (flag) //2
if (flag) //3
System.out.println("False True");
else //4
System.out.println("True False");
else //5
System.out.println("True True");
else //6
System.out.println("False False");
}
Which of the following statements are correct?
Select 2 options
A. If run with an argument of 'false', it will print 'False False'
B. If run with an argument of 'false', it will print 'True True'
C. If run with an argument of 'true', it will print 'True False'
D. It will never print 'True True'
E. It will not compile.
Submitted by c-admin on Tue, 05/28/2019 - 05:17
What will the following method return if called with an argument of 7?
public int transformNumber(int n){
int radix = 2;
int output = 0;
output += radix*n;
radix = output/radix;
if(output<14){
return output;
}
else{
output = output*radix/2;
return output;
}
else {
return output/2;
}
}
Select 1 option
A. 7
B. 14
C. 49
D. Compilation fails.
Submitted by c-admin on Tue, 05/28/2019 - 05:08
What will the following code print when run?
public class TestClass {
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "B" : System.out.println( "big bat" );
default : System.out.println( "none" );
}
}
public static void main(String[] args) throws Exception {
TestClass tc = new TestClass();
tc.switchString("B");
}
}
Select 1 option
A. bat
big bat
B. big bat
none
C. big bat
D. bat
E. The code will not compile.
Pages