Q36
Which statements concerning the relationships between the following classes are true?
class Foo {
int num;
Baz comp = new Baz();
}
class Bar {
boolean flag;
}
class Baz extends Foo {
Bar thing = new Bar();
double limit;
}
1) A Bar is a Baz.
2) A Foo has a Bar.
3) A Baz is a Foo.
4) A Foo is a Baz.
5) A Baz has a Bar.
Q37
Which statements concerning the value of a member variable are true, when no explicit assignments have been made?
1) The value of an int is undetermined.
2) The value of all numeric types is zero.
3) The compiler may issue an error if the variable is used before it is initialized.
4) The value of a String variable is "" (empty string).
5) The value of all object variables is null.
Q38
Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?
1) Objects are deleted when they can no longer be accessed through any reference.
2) The finalize() method will eventually be called on every object.
3) The finalize() method will never be called more than once on an object.
4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.
5) The garbage collector will use a mark and sweep algorithm.
Q39
Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?
CODE FRAGMENT A:
public static void main(String args[]) {
if (args.length != 0)
System.out.println(args[args.length-1]);
}
CODE FRAGMENT B:
public static void main(String args[]) {
try { System.out.println(args[args.length]); }
catch (ArrayIndexOutOfBoundsException e) {}
}
CODE FRAGMENT C:
public static void main(String args[]) {
int ix = args.length;
String last = args[ix];
if (ix != 0) System.out.println(last);
}
CODE FRAGMENT D:
public static void main(String args[]) {
int ix = args.length-1;
if (ix > 0) System.out.println(args[ix]);
}
CODE FRAGMENT E:
public static void main(String args[]) {
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}
}
1) Code fragment A.
2) Code fragment B.
3) Code fragment C.
4) Code fragment D.
5) Code fragment E.