Q23
Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?
public class Qf575 {
// insert declaration of a native method here
}
1) native public void setTemperature(int kelvin);
2) private native void setTemperature(int kelvin);
3) protected int native getTemperature();
4) public abstract native void setTemperature(int kelvin);
5) native int setTemperature(int kelvin) {}
Q24
How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components?
1) It affects which grid cell the components end up in.
2) It affects how the extra vertical space is distributed.
3) It affects the alignment of each component.
4) It affects whether the components completely fill their allotted display area vertically.
Q25
Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?
public class Q4a39 {
int a = 1;
int b = 1;
int c = 1;
class Inner {
int a = 2;
int get() {
int c = 3;
// insert statement here
return c;
}
}
Q4a39() {
Inner i = new Inner();
System.out.println(i.get());
}
public static void main(String args[]) {
new Q4a39();
}
}
1) c = b;
2) c = this.a;
3) c = this.b;
4) c = Q4a39.this.a;
5) c = c;
Q26
Which is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done?
public class Q76a9 {
static String f() {
String a = "hello";
String b = "bye"; // (0)
String c = b + "!"; // (1)
String d = b;
b = a; // (2)
d = a; // (3)
return c; // (4)
}
public static void main(String args[]) {
String msg = f();
System.out.println(msg); // (5)
}
}
1) The line marked (1).
2) The line marked (2).
3) The line marked (3).
4) The line marked (4).
5) The line marked (5).
Q27
Which methods from the String and StringBuffer classes modify the object on which they are called?
1) The charAt() method of the String class.
2) The toUpperCase() method of the String class.
3) The replace() method of the String class.
4) The reverse() method of the StringBuffer class.
5) The length() method of the StringBuffer class.
Q28
Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?
class A {}
class B extends A {}
class C extends A {}
public class Q3ae4 {
public static void main(String args[]) {
A x = new A();
B y = new B();
C z = new C();
// insert statement here
}
}
1) x = y;
2) z = x;
3) y = (B) x;
4) z = (C) y;
5) y = (A) y;