1.
Choose the possible constructor arguments of the Float wrapper class.
A. 
B. 
C. 
D. 
E. 
2.
Integer y = 567;
Integer x = y;
System.out.println(y==x);
y++;
System.out.println(x + " " + y);
System.out.println(y==x);
A. 
B. 
C. 
D. 
3.
Class Boxing2 {
static Integer x;
public static void main(String [] args) {
doStuff(x);
}
static void doStuff(int z) {
int z2 = 5;
System.out.println(z2 + z);
} }
From the above code,
Will it throws a NullPointerException?
4.
Class EasyOver {
static void go(int x) { System.out.print("int "); }
static void go(long x) { System.out.print("long "); }
static void go(double x) { System.out.print("double "); }
public static void main(String [] args) {
byte b = 5;
short s = 5;
long l = 5;
float f = 5.0f;
go(b);
go(s);
go(l);
go(f);
}
}
Predict the output of the above code.
A. 
B. 
C. 
D. 
5.
Class AddBoxing {
static void go(Integer x) { System.out.println("Integer"); }
static void go(long x) { System.out.println("long"); }
public static void main(String [] args) {
int i = 5;
go(i);
}
}
Which go() will be invoked?
(choose 1)
A. 
B. 
C. 
D. 
6.
Class BoxAndWiden {
static void go(Object o) {
Byte b2 = (Byte) o;
System.out.println(b2);
}
public static void main(String [] args) {
byte b = 5;
go(b);
}
}
What will be the output of above program?
A. 
B. 
C. 
D. 
7.
public class Test {
public static void main(String[] args) {
Integer in = 1;
int i = 1;
System.out.print(in.equals(i));
System.out.print(in == i);
}}
What will be the result of above code ?
A. 
B. 
C. 
D. 
8.
public class Test {
public static void main(String[] args) {
Number i=10;
int j = 10;
if (i.equals(j))
{
System.out.println("equals");
}
else
System.out.println("not equals");
}
}
what will be the result of above code?
A. 
B. 
C. 
Compile time error at line 3
D. 
Compile time error at line 5
9.
Examine:
1 public class Test3 {
2 static void pass(int i) {
}
3 static void pass(Integer i) {
4 System.out.println(i);
}
5 public static void main(String[] args) {
6 pass(1);
}
}
What will be the result of above code ?
A. 
B. 
Compile time error at line no 2.
C. 
D. 
Compile time error at line no 6.
10.
1 public class Test2 {
2 public static void main(String[] args) {
3 int i = 1;
4 Integer I = new Integer(i);
5 method(i);
6 method(I);
7 }
8 static void method(Integer I) {
9 System.out.print(" Wrapper");
10 }
11 static void method(int i) {
12 System.out.print(" Primitive");
}}
What will be the result of above code ?
A. 
B. 
C. 
D. 
11.
1. public class Test {
2. public static void main(String [ ] args) {
3.
4. switch(a) {
5. default:
6. System.out.println("You choose correct option");
7. } } }
Which given below snippet is best for inserting at line number 3 to compile the above code
successfully.
(choose 3)
A. 
B. 
C. 
D. 
E. 
12.
1 .public class LoopOutput{
2. public static void main(String args[]) {
3. int a = 4;
4. int b = 3;
5. int c = 2;
6. for(;b < 7;b++) {
7. if(c++ > a) {
8. a = b + c;
9. }
11. }
12. System.out.println("Value of C is " + c);
13. }
14. }
What is the output of variable "c" after completion of for loop :
A. 
B. 
C. 
D. 
13.
1 .public class Question3{
2 .public static void main(String[] args) {
3 .try {
4 .int a= (int)(Math.random()*5);
5 .if(a<=2.5)
6 .System.out.println("a="+a);
7 .else
8 .throw new Exception("a>2.5");
9. } catch (Exception e){
10. System.err.println(e.getMessage() );
11. System.err.println("Value of a="+a);
12. } } }
Find the output of the following code :
A. 
An Exception is raised during compilation
B. 
An Exception is thrown at run time
C. 
Unresolved compilation problem
D. 
A=2 or a=1 or i >2.5 Value of i =null
14.
1. import java.io.*;
2. public class Example4 {
3. public static void main(String[] args) {
4. Example4 e4 = new Example4();
5. try{
6. e4.check();}
7. catch(IOException e){}}
8. void check() throws IOException{
9. System.out.println("Inside check() method of Class ");
10. throw new IOException();}}
11. class Subexample4 extends Example4 {
12. void check() {
13. System.out.println("Inside check() Method of Subclass");
14. }}
What will be the output of the following code snippet :
A. 
Above program will throw exception & will not run
B. 
Inside check() method of class
C. 
Inside check() method of Subclass
15.
What should be at line number 3 to get the total sum of array "sum" ?
public int totalsum( int[] sum ){
int a, b= 0 ;
//which 'for' loop should be here(line :3)
{
b += sum[ a++ ] ;
}
return b ;
}
Which 'for' loop should be at line number 3 to calculate total sum of the array "sum" :
A. 
for( int a = 0 ; a< sum.length ; )
B. 
For( a= 0 ; a< sum.length ; )
C. 
For( a = 0 ; a< sum.length ; a++ )
D. 
16.
Which modifier should used in place of **** , so that it's subclass saved in other package can access " FixVariable() " method of it's super class ?
package NewPackage;
public class Example extends rose{
private int length;
*** void FixVariable( int a ) {
length = a;
}
}
// subclass in different package
import NewPackage.Example ;
public class SubExample extends Example {
SubExample() {
FixVariable( 201 );
}
A. 
B. 
C. 
D. 
17.
Public class Example6{
public static void main(String args[])
{
public int check(char a) {
if (a <= 'N') {
if (a == 'E')
return 2;
return 1;
} else if (a == 'S')
return 3;
else if (a == 'W')
return 4;
return 0; }
}
}
Which are correct input-output options :
(choose 2)
A. 
B. 
C. 
D. 
18.
What is the output of the following 'for' loop code :
public class Example12 {
public static void main(String[] args) {
int a, b;
flag: for (a = 0; a < 6; a++) {
for (b = 5; b > 2; b--) {
if (a == b) {
System.out.print(" " + b);
continue flag;
}
}
}
}
}}
A. 
B. 
C. 
D. 
19.
What would be the output after executing following code :
public class Example13 {
public static void main(String[] args) throws Exception {
int a = 30;
while (a) {
System.out.print("value:" + a--);
}
}
}
A. 
B. 
C. 
D. 
20.
Find the Output of the following code :
public class Example15 {
public static void main(String[] args) {
for (int a = 0; a < 10; ++a) {
try {
if (a % 3 == 0)
throw new Exception("Except1");
try {
if (a % 3 == 1)
throw new Exception("Except2");
System.out.println(a);
} catch (Exception inside) {
a *= 2;
} finally {
++a;
}
} catch (Exception outside) {
a += 3;
} finally {
++a;
}
}
}
}
A. 
B. 
C. 
D. 
21.
Given a sample code:
1 public class Sample {
2 public static void main(String args[]) {
3 int k=1, m=3;
4 do {
5 k=++k;
6 m--;
7 } while(m>0);
8 System.out.println(k);
9 }}
What will be the result of above code ?
A. 
B. 
C. 
D. 
The program compilation fails because of line number 5.
22.
Given a sample code:
1 public class Sample{
2 public static void main(String args[]) {
3 int i = 1, j = 2;
4 i++;
5 j--;
6 if (i / j > 1)
7 i++;
8 System.out.println(i + j);
}}
What will be the result of above code ?
A. 
B. 
C. 
D. 
The program compilation fails because of line number 6.
23.
Given a sample code:
1 public class Sample {
2 public static void main(String args[]) {
3 int i = 1, j = 2;
4 i++;
5 j--;
6 if (i % j > 1)
7 i++;
8 System.out.println("i = "+i+ " j = "+j);
}}
What will be the result of above code ?
A. 
B. 
C. 
D. 
The program compilation fails because of line number 6.
24.
Given a sample code:
1 public class Test {
2 public static void main(String args[]) {
3 int i = 5;
4 do {
5 i--;
6 } while (i > 2);
7 System.out.println(i);
8 }}
What will be the result of above code ?
A. 
B. 
C. 
D. 
The program compilation fails because of line number 6.
25.
Given a sample code:
1 public class Test {
2 public static void main(String args[]) {
3 int j;
4 do {
5 j++;
6 }
7 while(j < 0);
8 System.out.println(j);
}}
What will be the result of above code ?
A. 
The program compilation fails because of line number 3.
B. 
C. 
D. 
The program compilation fails because of line number 5.