Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
Which of these statements are legal. Select the three correct answers.
a.
int arr[][] = new int[5][5];
b.
int []arr[] = new int[5][5];
c.
int[][] arr = new int[5][5];
d.
int[] arr = new int[5][];
e.
int[] arr = new int[][5];
(A) a, b
(B) a, b, c
(C) a, b, c, d
(D) a, b, c, d, e
Ques 2 :
What should be done to invoke the run() method on a thread for an object derived from the Thread class. Select the one correct answer.
(A) The run() method should be directly invoked on the Object.
(B) The start() method should be directly invoked on the Object.
(C) The init() method should be directly invoked on the Object.
(D) The creation of the object using the new operator would create a new thread and invoke its run() method.
Ques 3 :
class Test
{
public static void main(String [] args) throws Exception
{
Vector data = new Vector();
data.add("apple");
data.add("mango");
data.add("papaya");
data.add("cherry");
data.add("banana");
data.add("apple");
System.out.println(getData(data));
}
public static Vector getData(Vector v)
{
return new Vector(new HashSet(v));
}
}
What would be the output?
(A) Compile Error
(B) [banana, cherry, papaya, apple, mango]
(C) [banana, cherry, papaya, apple, mango]
(D) [banana, cherry, papaya, apple, apple, mango]
Ques 4 :
A top level class may have only the following access modifier. Select the one correct answer.
(A) package
(B) protected
(C) private
(D) public
Ques 5 :
Using up to four characters, write the Java representation of integer literal 3 in hexadecimal.
(A) 0x03, 0X03, 0X3
(B) 0x04, 0X04, 0X4
(C) 0x05, 0X05, 0X5
(D) none of these
Ques 6 :
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 7 :
Which of the following statements declare class Sample to belong to the payroll.admindept package?
(A) package payroll;package admindept;
(B) package payroll.admindept.Sample;
(C) package payroll.admindept;
(D) import payroll.admindept.*
Ques 8 :
Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
(A) valueOf
(B) intValue
(C) getInt
(D) getInteger
Ques 9 :
What is the result of compiling and running this program? Select the one correct answer.
public class test
{
public static void main(String args[])
{
int i, j;
int k = 0;
j = 2;
k = j = i = 1;
System.out.println(k);
}
}
(A) The program does not compile as k is being read without being initialized.
(B) The program does not compile because of the statement k = j = i = 1;
(C) The program compiles and runs printing 1.
(D) The program compiles and runs printing 2.
Ques 10 :
Which of these are legal identifiers.
(A) number_1
(B) number_a
(C) $1234
(D) All of the above.
Ques 11 :
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 12 :
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 13 :
What is the default priority of a newly created thread.?
(A) MIN_PRIORITY (which is defined as 1 in the Thread class.)
(B) NORM_PRIORITY (which is defined as 5 in the Thread class.)
(C) MAX_PRIORITY (which is defined as 10 in the Thread class.)
(D) A thread inherits the priority of its parent thread.
Ques 14 :
Which of the following are valid constructors within a class Test. Select the two correct answers.
a.
test() { }
b.
Test() { }
c.
void Test() { }
d.
private final Test() { }
e.
abstract Test() { }
f.
Test(Test t) { }
g.
Test(void) { }
(A) b, d
(B) c, f
(C) b, c
(D) b, f
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 :
Which of the following statements are correct. Select the one correct answer.
(A) Each Java file must have exactly one package statement to specify where the class is stored.
(B) If a Java file has both import and package statement, the import statement must come before package statement.
(C) A Java file has at least one class defined.
(D) If a Java file has a package statement, it must be the first statement (except comments).
Ques 17 :
How can you ensure that the memory allocated by an object is freed. Select the one correct answer.
(A) By invoking the free method on the object.
(B) By calling system.gc() method.
(C) By setting all references to the object to new values (say null).
(D) Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.
Ques 18 :
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;
x = -3 >> 1;
x = x >>> 2;
x = x << 1;
System.out.println(x);
}
}
(A) 7
(B) 23
(C) 5
(D) 2147483646
Ques 19 :
Which of the following statements is true?
(A) An exception can be thrown by throw keyword explicitly.
(B) An exception can be thrown by throws keyword explicitly.
Ques 20 :
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
Submit Answer
Don't Refresh the Page !! ...