Time remaining
:
:
Test Status
COREJAVARANDOMTEST
Ques 1 :
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 2 :
The class Hashtable is used to implement which collection interface. Select the one correct answer.
(A) List
(B) Set
(C) Map
(D) SortedSet
Ques 3 :
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 4 :
Which of the following statements is false about objects?
(A) An instance of a class is an object
(B) Objects can access both static and instance data
(C) Objects do not permit encapsulation
(D) Object is the super class of all other classes
Ques 5 :
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 6 :
Which operator is used to perform bitwise exclusive or.
(A) &
(B) ^
(C) |
(D) !
Ques 7 :
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[] arr = {1,2,3,4};
call_array(arr[0], arr);
System.out.println(arr[0] + "," + arr[1]);
}
static void call_array(int i, int arr[])
{
arr[i] = 6;
i = 5;
}
}
(A) 1,2
(B) 5,2
(C) 1,6
(D) 5,6
Ques 8 :
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 9 :
What is the range of values that can be specified for an int. Select the one correct answer.
(A) The range of values is compiler dependent.
(B) -231 to 231 - 1
(C) 231-1 to 231
(D) -215 to 215 - 1
Ques 10 :
nt index = 1;
Boolean [] test = new Boolean[3];
Boolean data = test[index];
What is the result?
(A) data has the value of true
(B) The code will not compile.
(C) data has the value of false
(D) data has the value of null
Ques 11 :
Which of these statements is true?
(A) AbstractSet extends Set
(B) LinkedList extends List
(C) HashSet extends AbstractSet
(D) WeakHashMap extends HashMap
Ques 12 :
What is the data type for the number 9.6352?
(A) float
(B) double
(C) Float
(D) Double
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[]) {
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 14 :
Select the one correct answer. The number of characters in an object of a class String is given by
(A) The member variable called size
(B) The member variable called length
(C) The method size() returns the number of characters.
(D) The method length() returns the number of characters.
Ques 15 :
Why we use @Override annotation?
(A) To check whether the subclass method is overrides from the superclass or not
(B) To say to the compiler not to execute this override method.
(C) To say to compiler that this method is deprecated
(D) None of the above
Ques 16 :
When we go for thread synchronization?
(A) to remove the lock on the thread
(B) when there is a single thread
(C) to make a thread in sleep mode
(D) when we want to prevent any other multiple thread to act an same object
Ques 17 :
What gets printed when the following program is compiled and run. Select the one correct answer.
public class incr {
public static void main(String args[]) {
int i , j;
i = j = 3;
int n = 2 * ++i;
int m = 2 * j++;
System.out.println(i + " " + j + " " + n + " " + m);
}
}
(A) 4 4 8 6
(B) 4 4 8 8
(C) 4 4 6 6
(D) 4 3 8 6
Ques 18 :
What happens if sleep() and wait() executes in synchronized block?
(A) The object still under lock in both the cases
(B) sleep() the lock is removed ,wait() still under lock
(C) sleep() still under lock ,wait() the lock is removed
(D) Sleep() and wait(),for both the method lock is removed
Ques 19 :
Which code determines the int value data closer to, but not greater than, a double value b?
(A) Int data = (int) Math.floor(b);
(B) Int data = (int) Math.abs(b);
(C) Int data = (int) Math.ceil(b);
(D) Int data = (int) Math.min(b);
Ques 20 :
Which of these are Java keywords. Select the five correct answers
a.
TRUE
b.
volatile
c.
transient
d.
native
e.
interface
f.
then
g.
new
(A) b, d, f, g
(B) a, b, d, g
(C) b, c, d, e, g
(D) d, e, f, g
Submit Answer
Don't Refresh the Page !! ...