Q: What will be the value of y after execution of switch statement?
public class Test{
public static void main(String[] args){
int x = 3, y = 4;
switch(x + 3){
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}
}
}
A.1
B.2
C. 3
D.4
Correct Option: BExplanation: 2
Q: What will be the result?
1. int i = 10;
2. while(i++ <= 10){
3. i++;
4. }
5. System.out.print(i);
A.10
B. 11
C.12
D.13
Correct Option: DExplanation: 13
Q: What is the printout of the following switch statement?
char ch = 'a';
switch (ch){
case 'a':
case 'A': System.out.print(ch); break;
case 'b':
case 'B': System.out.print(ch); break;
case 'c':
case 'C': System.out.print(ch); break;
case 'd':
case 'D': System.out.print(ch);
}
A.abcd
B.aa
C.a
D.ab
Correct Option: CExplanation: a
Q: How many times will the following code print "Welcome to Examveda"?
int count = 0;
do {
System.out.println("Welcome to Examveda");
count++;
} while (count < 10);
A.8
B.9
C.10
D.11
Correct Option: CExplanation: 10
Q: What will be the result of the following code?
public class Test{
static public void main(String args[]){ //line 2
int i, j;
for(i=0; i<3; i++){
for(j=1; j<4; j++){
i%=j;
System.out.println(j);
}
}
}
}
A.1 2 3 1
B.1 2 3 2
C. Repeatedly print 1 2 3 and cause infinite loop.
D.Compilation fails because of line 2
Correct Option: CExplanation: Repeatedly print 1 2 3 and cause infinite loop.
Q: What will be the result of compiling and runnig the following code:
public class Test{
public static void main(String... args) throws Exception{
Integer i = 34;
int l = 34;
if(i.equals(l)){
System.out.println("true");
}else{
System.out.println("false");
}
}
}
A.true
B. false
C.Compiler error
D.None of these
Correct Option: AExplanation: true
Q: Which option, inserted at line 4, produces the output 12?
1. public class Test{
2. public static void main(String [] args){
3. int x = 0;
4. // insert code here
5. do{ } while(x++ < y);
6. System.out.println(x);
7. }
8. }
A.int y = x;
B.int y = 10;
C.int y = 11;
D. int y = 12;
Correct Option: CExplanation: int y = 11;
Q: Determine output:
public class Test{
public static void main(String args[]){
int i, j;
for(i=1, j=0;i<10;i++) j += i;
System.out.println(i);
}
}
A.10
B.11
C.9
D.20
Correct Option: AExplanation: 10
Q: Determine output:
public class Test{
public static void main(String args[]){
int i;
for(i = 1; i < 6; i++){
if(i > 3) continue ;
}
System.out.println(i);
}
}
A.2
B. 3
C. 4
D.6
Correct Option: DExplanation: 6
Q: What will be the output?
public class Test{
public static void main(String[] args){
int x=10, y=0;
if(x && y){
System.out.print("TRUE");
}
else{
System.out.print("FALSE");
}
}
}