Which code fragments print 1?

Which code fragments print 1?

Which code fragments print 1?

A.
String arr [] = {“1”, “2”, “3”};
List <? extendsString > arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));

B.
String arr [] = {“1”, “2”, “3”};
List <Integer> arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));

C.
String arr [] = {“1”, “2”, “3”};
List <?> arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));

D.
String arr [] = {“1″,”2″,”3”};
List <?> arrList = new LinkedList <?>(Arrays.asList (arr));
System.out.println (arrList.get (0));

E.
String arr [] = {“1″,”2″,”3”};
List <Integer> extendsString > arrList =new LinkedList <Integer> (Arrays.asList (arr));
System.out.println (arrList.get (0));

Explanation:

Note:You can replace the type arguments required to invoke the constructor of a generic class
with an empty set of type parameters (<>) as long as the compiler can infer the type arguments
from the context. This pair of angle brackets is informally called the diamond.



Leave a Reply 1

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


Pavithra Rao

Pavithra Rao

Ans: A,D