Which two, inserted at line 11, will allow the code to compile? (Choose two.)

Given:

11. //insert code here
12. private N min, max;
13. public N getMin() { return min; }
14. public N getMax() { return max; }
15. public void add(N added) {
16. if (min == null || added.doubleValue() < min.doubleValue())
17. min = added;
18. if (max == null || added.doubleValue() > max.doubleValue())
19. max = added;
20. }
21. }

Which two, inserted at line 11, will allow the code to compile? (Choose two.)

Given:

11. //insert code here
12. private N min, max;
13. public N getMin() { return min; }
14. public N getMax() { return max; }
15. public void add(N added) {
16. if (min == null || added.doubleValue() < min.doubleValue())
17. min = added;
18. if (max == null || added.doubleValue() > max.doubleValue())
19. max = added;
20. }
21. }

Which two, inserted at line 11, will allow the code to compile? (Choose two.)

A.
public class MinMax<?> {

B.
public class MinMax<? extends Number> {

C.
public class MinMax<N extends Object> {

D.
public class MinMax<N extends Number> {

E.
public class MinMax<? extends Object> {

F.
public class MinMax<N extends Integer> {

Explanation:
A:
12 compilation errors

B:
Main.java:11: <identifier> expected
class MinMax<? extends Number> {
^
Main.java:11: ‘{‘ expected
class MinMax<? extends Number> {
^
2 errors

C:
Main.java:16: cannot find symbol
symbol : method doubleValue()
location: class java.lang.Object
if (min == null || added.doubleValue() < min.doubleValue())
^
Main.java:16: cannot find symbol
symbol : method doubleValue()
location: class java.lang.Object
if (min == null || added.doubleValue() < min.doubleValue())
^
Main.java:18: cannot find symbol
symbol : method doubleValue()
location: class java.lang.Object
if (max == null || added.doubleValue() > max.doubleValue())
^
Main.java:18: cannot find symbol
symbol : method doubleValue()
location: class java.lang.Object
if (max == null || added.doubleValue() > max.doubleValue())
^
4 errors

D:
compiled successfully

E:
Main.java:1: <identifier> expected
class MinMax<? extends Object> {
^
Main.java:1: ‘{‘ expected
class MinMax<? extends Object> {
^
2 errors

F:
compiled successfully



Leave a Reply 0

Your email address will not be published. Required fields are marked *