Time remaining
:
:
Test Status
CORETEST5
Ques 1 :
Which of the following is not a return type?
(A) boolean
(B) void
(C) public
(D) Button
Ques 2 :
What would happen when the following is compiled and executed. Select the one correct answer.
public class Compare {
public static void main(String args[]) {
int x = 10, y;
if(x < 10)
y = 1;
if(x>= 10) y = 2;
System.out.println("y is " + y);
}
}
(A) The program compiles and prints y is 0 when executed.
(B) The program compiles and prints y is 1 when executed.
(C) The program compiles and prints y is 2 when executed.
(D) The program does not compile complaining about y not being initialized.
Ques 3 :
Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b) . Select the one correct answer.
(A) a + b
(B) a - b
(C) b - a
(D) b - a - 1
Ques 4 :
Which operator is used to perform bitwise exclusive or.
(A) &
(B) ^
(C) |
(D) !
Ques 5 :
What all gets printed when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int i=0, j=2;
do {
i=++i;
j--;
} while(j>0);
System.out.println(i);
}
}
(A) 0
(B) 1
(C) 2
(D) The program does not compile because of statement "i=++i;"
Ques 6 :
If result = 2 + 3 * 5, what is the value and type of â??resultâ?? variable?
(A) 17, byte
(B) 25, byte
(C) 17, int
(D) 25, int
Ques 7 :
What is the data type for the number 9.6352?
(A) float
(B) double
(C) Float
(D) Double
Ques 8 :
What would happen when the following is compiled and executed. Select the one correct answer.
class example {
int x;
int y;
String name;
public static void main(String args[]) {
example pnt = new example();
System.out.println("pnt is " + pnt.name +
" " + pnt.x + " " + pnt.y);
}
}
(A) The program does not compile because x, y and name are not initialized.
(B) The program throws a runtime exception as x, y, and name are used before initialization.
(C) The program prints pnt is 0 0.
(D) The program prints pnt is null 0 0.
Ques 9 :
The initial value of an instance variable of type String that is not explicitly initialized in the program is --. Select the one correct answer.
(A) null
(B) ""
(C) NULL
(D) The instance variable must be explicitly assigned.
Ques 10 :
The initial value of a local variable of type String that is not explicitly initialized and which is defined in a member function of a class. Select the one correct answer.
(A) NULL
(B) ""
(C) null
(D) The local variable must be explicitly assigned.
Ques 11 :
What is the result of compiling and running the following program. Select the one correct answer.
class test {
public static void main(String args[]) {
char ch;
String test2 = "abcd";
String test = new String("abcd");
if(test.equals(test2)) {
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else {
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}
(A) 'a'
(B) 'b'
(C) 'c'
(D) 'd'
Ques 12 :
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
boolean x = true;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
System.out.println(a);
}
}
(A) 1
(B) 2
(C) 3
(D) 4
Ques 13 :
What is the result of compiling and running the following program. Select the one correct answer.
class test {
public static void main(String args[]) {
int i,j=0;
for(i=10;i<0;i--) { j++; }
switch(j) {
case (0) :
j=j+1;
case(1):
j=j+2;
break;
case (2) :
j=j+3;
break;
case (10) :
j=j+10;
break;
default :
break;
}
System.out.println(j);
}
}
(A) 1
(B) 2
(C) 0
(D) 3
Ques 14 :
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
boolean x = false;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
System.out.println(a);
}
}
(A) 1
(B) 2
(C) 3
(D) 4
Ques 15 :
What all gets printed when the following gets compiled and run. Select the three correct answers.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
a.
0
b.
1
c.
2
d.
3
e.
4
(A) a, b, c
(B) b, c, d
(C) a, d, e
(D) a, c, d
Ques 16 :
Assume that the value 3929.92 is of type â??floatâ??. How to assign this value after declaring the variable â??interestâ?? of type float?
(A) interest = 3929.92
(B) interest = (Float)3929.92
(C) interest = 3929.92 (float)
(D) interest = 3929.92f
Ques 17 :
Which of the following are legal Java programs. Select the four correct answers.
a.
// The comments come before the package
package pkg;
import java.awt.*;
class C{}
b.
package pkg;
import java.awt.*;
class C{}
c.
package pkg1;
package pkg2;
import java.awt.*;
class C{}
d.
package pkg;
import java.awt.*;
e.
import java.awt.*;
class C{}
f.
import java.awt.*;
package pkg;
class C {}
(A) a, b, c, d
(B) a, b, d, e
(C) b, c, d, e
(D) c, d, e, f
Ques 18 :
What is the number displayed when the following program is compiled and run.
class test {
public static void main(String args[]) {
test test1 = new test();
System.out.println(test1.xyz(100));
}
public int xyz(int num) {
if(num == 1) return 1;
else return(xyz(num-1) + num);
}
}
(A) 4040
(B) 5050
(C) 4045
(D) 5055
Ques 19 :
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int x, y;
x = 5 >> 2;
y = x >>> 2;
System.out.println(y);
}
}
(A) 5
(B) 2
(C) 80
(D) 0
Ques 20 :
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
a.
0
b.
1
c.
2
d.
3
e.
4
(A) a, b
(B) b, c
(C) c, d
(D) d, e
Submit Answer
Don't Refresh the Page !! ...