Q29
Which of these are keywords in Java?
1) default
2) NULL
3) String
4) throws
5) long
Q30
It is desirable that a certain method within a certain class can only be accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced?
1) Mark the method with the keyword public.
2) Mark the method with the keyword protected.
3) Mark the method with the keyword private.
4) Mark the method with the keyword package.
5) Do not mark the method with any accessibility modifiers.
Q31
Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab[3][2] to access a valid element?
CODE FRAGMENT A:
int[][] tab = {
{ 0, 0, 0 },
{ 0, 0, 0 }
};
CODE FRAGMENT B:
int tab[][] = new int[4][];
for (int i=0; i
CODE FRAGMENT C:
int tab[][] = {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
CODE FRAGMENT D:
int tab[3][2];
CODE FRAGMENT E:
int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
1) Code fragment A.
2) Code fragment B.
3) Code fragment C.
4) Code fragment D.
5) Code fragment E.
Q32
What will be the result of attempting to run the following program?
public class Qaa75 {
public static void main(String args[]) {
String[][][] arr = {
{ {}, null },
{ { "1", "2" }, { "1", null, "3" } },
{},
{ { "1", null } }
};
System.out.println(arr.length + arr[1][2].length);
}
}
1) The program will terminate with an ArrayIndexOutOfBoundsException.
2) The program will terminate with a NullPointerException.
3) 4 will be written to standard output.
4) 6 will be written to standard output.
5) 7 will be written to standard output.
Q33
Which expressions will evaluate to true if preceded by the following code?
String a = "hello";
String b = new String(a);
String c = a;
char[] d = { 'h', 'e', 'l', 'l', 'o' };
1) (a == "Hello")
2) (a == b)
3) (a == c)
4) a.equals(b)
5) a.equals(d)
Q34
Which statements concerning the following code are true?
class A {
public A() {}
public A(int i) { this(); }
}
class B extends A {
public boolean B(String msg) { return false; }
}
class C extends B {
private C() { super(); }
public C(String msg) { this(); }
public C(int i) {}
}
1) The code will fail to compile.
2) The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C.
3) Class C has three constructors.
4) Objects of class B cannot be constructed.
5) At most one of the constructors of each class is called as a result of constructing an object of class C.
Q35
Given two collection objects referenced by col1 and col2, which of these statements are true?
1) The operation col1.retainAll(col2) will not modify the col1 object.
2) The operation col1.removeAll(col2) will not modify the col2 object.
3) The operation col1.addAll(col2) will return a new collection object,
containing elements from both col1 and col2.
4) The operation col1.containsAll(Col2) will not modify the col1 object.