Q50
Given the following interface definition, which definitions are valid?
interface I {
void setValue(int val);
int getValue();
}
DEFINITION A:
(a) class A extends I {
int value;
void setValue(int val) { value = val; }
int getValue() { return value; }
}
DEFINITION B:
(b) interface B extends I {
void increment();
}
DEFINITION C:
(c) abstract class C implements I {
int getValue() { return 0; }
abstract void increment();
}
DEFINITION D:
(d) interface D implements I {
void increment();
}
DEFINITION E:
(e) class E implements I {
int value;
public void setValue(int val) { value = val; }
}
1) Definition A.
2) Definition B.
3) Definition C.
4) Definition D.
5) Definition E.
Q51
Which statements concerning the methods notify() and notifyAll() are true?
1) Instances of class Thread have a method called notify().
2) A call to the method notify() will wake the thread that currently owns the monitor of the object.
3) The method notify() is synchronized.
4) The method notifyAll() is defined in class Thread.
5) When there is more than one thread waiting to obtain the monitor of an object, there is no way to be sure which thread will be notified by the notify() method.
Q52
Which statements concerning the correlation between the inner and outer instances of non-static inner classes are true?
1) Member variables of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers.
2) Member variables of the outer instance can never be referred to using only the variable name within the inner instance.
3) More than one inner instance can be associated with the same outer instance.
4) All variables from the outer instance that should be accessible in the inner instance must be declared final.
5) A class that is declared final cannot have any inner classes.
Q53
What will be the result of attempting to compile and run the following code?
public class Q6b0c {
public static void main(String args[]) {
int i = 4;
float f = 4.3;
double d = 1.8;
int c = 0;
if (i == f) c++;
if (((int) (f + d)) == ((int) f + (int) d)) c += 2;
System.out.println(c);
}
}
1) The code will fail to compile.
2) 0 will be written to the standard output.
3) 1 will be written to the standard output.
4) 2 will be written to the standard output.
5) 3 will be written to the standard output.