Q. Find the output
class Demo {
public static void main(String args[]) {
for (int i =0; i <3; i++) {
switch(i) {
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");
}
}
A. done
B. one two three done
C. one two three two three done
D. one two three one three one two done
Ans. C
Q. Find the output
class Demo {
public static void main(String args[]) {
int index = 0;
boolean flag = true;
boolean a = false, b;
b = (flag | ((index++) == 0));
b = (a | ((index += 2) > 0));
System.out.println(index);
}
}
A. 0
B. 1
C. 2
D. 3
Ans. D
Q. Find the output
class Demo {
public static void main() {
int odd = 1;
if (odd) {
System.out.println("odd");
} else {
System.out.println("even");
}
}
}
A. odd
B. even
C. odd even
D. Error
Ans. D
Q. Find the output
class Demo {
public static void main(String [] args) {
char ch = 'G';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);
}
}
A. 5 G
B. 76 G
C. 71 G
D. Error : Can’t append int to string
Ans. B
Q. Find the output
class Demo {
public static void main(String args[]) {
for (int i =0.0; i <3.0; i++) {
switch(i) {
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");
}
}
A. done
B. one two three done
C. Runtime Error
D. one two three one three one two done
Ans. C

class Teacher{
String name;
Teacher(){
System.out.println(“In Teacher class”);
}
}
class Student extends Teacher{
Student(){
System.out.println(“In Student class”);
}
int id;
public static void main(String a[]){
Student ob=new Student(); //Line 1
ob.name=”abcde”; //Line 2
ob.id=12345;}
}
Correct output should be: In Teacher class In Student class
Please modify option B