Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
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[]) {
String s1 = "abc";
String s2 = new String("abc");
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
(A) 1 3
(B) 1 4
(C) 2 3
(D) 2 4
Ques 2 :
Which operator is used to perform bitwise inversion in Java. Select the one correct answer.
(A) ~
(B) !
(C) &
(D) ^
Ques 3 :
Which of the following are legal declaration and definition of a method. Select all correct answers.
a.
void method() {};
b.
void method(void) {};
c.
method() {};
d.
method(void) {};
e.
void method {};
(A) a,b
(B) a
(C) a,b,c
(D) b,d,e
Ques 4 :
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 5 :
What will be the output of the program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
(A) Finally
(B) Compilation fails
(C) The code runs with no output.
(D) An exception is thrown at runtime.
Ques 6 :
What gets written on the screen when the following program is compiled and run. Select the one right answer.
public class test {
public static void main(String args[]) {
int i;
float f = 2.3f;
double d = 2.7;
i = ((int)Math.ceil(f)) * ((int)Math.round(d));
System.out.println(i);
}
}
(A) 4
(B) 5
(C) 6
(D) 9
Ques 7 :
Which of the following are true. Select the one correct answers.
(A) && operator is used for short-circuited logical AND.
(B) ~ operator is the bit-wise XOR operator.
(C) operator is used to perform bitwise OR and also short-circuited logical OR.
(D) The unsigned right shift operator in Java is >>.
Ques 8 :
Which statement about static inner class is true?
(A) A static inner class does not require an instance of the enclosing class.
(B) A static inner class cannot be a static member of outer class.
(C) It must extend enclosing class.
(D) Itâ??s variables and methods must be static.
Ques 9 :
Which of the following is a Java keyword. Select the four correct answers.
a.
extern
b.
synchronized
c.
volatile
d.
friend
e.
friendly
f.
transient
g.
this
h.
then
(A) b, c
(B) b, c, f, g
(C) e, g, h
(D) all of above.
Ques 10 :
Which of the following statements is true?
(A) A super class is a sub set of a sub class
(B) class ClassTwo extends ClassOne means ClassOne is a subclass
(C) class ClassTwo extends ClassOne means ClassTow is a super class
(D) the class Class is the super class of all other classes in Java.
Ques 11 :
What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j > i; j--)
assert i!=j {System.out.println(i); }
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The program generates a compilation error.
(D) The number 2 gets printed with AssertionError
Ques 12 :
Which are true among below cases?
(A) If programmer want to use several threads then he have to use StringBuffer
(B) StringBuffer Class is synchronized and StringBuilder is not synchronized
(C) String class is immutable, StringBuffer and StringBuilder are mutable
(D) All the above
Ques 13 :
Which of the following statements is preferred to create a string "Welcome to Java Programming"?
(A) String str = â??Welcome to Java Programmingâ??
(B) String str = new String( â??Welcome to Java Programmingâ?? )
(C) String str; str = â??Welcome to Java Programmingâ??
(D) String str; str = new String (â??Welcome to Java Programmingâ?? )
Ques 14 :
Which of these are valid declarations for the main method? Select the one correct answer.
(A) public void main();
(B) public static void main(String args[]);
(C) static public void main(String);
(D) public static int main(String args[]);
Ques 15 :
Which of the following are legal array declarations. Select the three correct answers.
a.
int i[5][];
b.
int i[][];
c.
int []i[];
d.
int i[5][5];
e.
int[][] a;
(A) a, d, e
(B) b, c, d
(C) b, c, e
(D) a, c, e
Ques 16 :
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,d,c
(B) b,c,a
(C) d,e
(D) a,b
Ques 17 :
What all gets printed when the following code is compiled and run. Select the three correct answers.
class test
{
public static void main(String args[])
{
int i[] = {0,1};
try
{
i[2] = i[0] + i[1];
}
catch(ArrayIndexOutOfBoundsException e1)
{
System.out.println("1");
}
catch(Exception e2)
{
System.out.println("2");
}
finally
{
System.out.println(3);
}
System.out.println("4");
}
}
a.
1
b.
2
c.
3
d.
4
(A) 1 2 4
(B) 4
(C) 1 3 4
(D) 1 2 3
Ques 18 :
Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer.
(A) arr.length
(B) arr.length - 1
(C) arr.size
(D) arr.length()
Ques 19 :
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class example {
public static void main(String args[]) {
int x = 0;
if(x > 0) x = 1;
switch(x) {
case 1: System.out.println(1);
case 0: System.out.println(0);
case 2: System.out.println(2);
break;
case 3: System.out.println(3);
default: System.out.println(4);
break;
}
}
}
A.
0
B.
1
C.
2
D.
3
E.
4
(A) 1, 0, 2
(B) 3, 4
(C) 0, 2
(D) 1
Ques 20 :
Which of these are interfaces in the collection framework. Select the two correct answers.
a.
HashMap
b.
ArrayList
c.
Collection
d.
SortedMap
e.
TreeMap
(A) a,b
(B) c,d
(C) d,e
(D) a,d
Submit Answer
Don't Refresh the Page !! ...