The return type of ring method is Queue<E>. E is anything that extends B, which is in this case C. Which means only objects of declared type Queue<C> can be assigned the return of ring method()
So, at line1 and line2 assigning the result to q1 (Queue<C> declared type object) will pass
But, at line3 and line 4 assigning the result to q2 (PriorityQueue<C> declared type object) will fail (cannot convert from Queue<C> to PriorityQueue<C>)
Now let's examine the type of the argument of method ring():
The declaration type of the argument is List<E>, E is anything that extends B, which is in this case C.
The passing parameter to method ring can be declared (declaration type) as List or any of List's sub types (ArrayList, LinkedList,..)
You can send non-generic lists of these types or generic list of these types. But, in case of sending a generic list, then the generic type of the List must be C
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |