These are questions from MindQ's
test.
1.
Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.
a) public static void main(
String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
The answer given are a,b and e.I think choice d is also correct,there is no restriction to throw unchecked exception
when overriding in subclasses.
2.How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
a) 0
b) 1
c) 2
d) 3
e) 4
The answer given is b.According to me the answer is a,because the ref name is assigned to anther object which is
referenced by ref newestName. So in order to make the object eligible for GC newestName also has to set to null.
3. What method(s) from the java.lang.Math class might method() be if the statement
method( -4.4 ) == -4;
is true.
a) round()
b) min()
c) trunc()
d) abs()
e) floor()
f) ceil()
The answers given are a and f.I don't agree with f,since ceil() returns only double and not int.(-4 is not equal to -4.0)
Correct me if i'm wrong!!