GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt abt Generics mock question - from K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt abt Generics mock question - from K&B" Watch "doubt abt Generics mock question - from K&B" New topic
Author

doubt abt Generics mock question - from K&B

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
Given a method declared as:



A programmer wants to use this method like this:

Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)
A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;
B. ArrayList<Integer> input = null;
List<Integer> output = null;
C. ArrayList<Integer> input = null;
List<Number> output = null;
D. List<Number> input = null;
ArrayList<Integer> output = null;
E. List<Number> input = null;
List<Number> output = null;
F. List<Integer> input = null;
List<Integer> output = null;
G. None of the above.

the answers are B, E and F.

as if B is "ArrayList<Integer> input = null",
WHY would process(input) works, as the method's parameter declared as process(List<E> nums), type of List not ArrayList?
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Because



Bu.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt abt Generics mock question - from K&B