Java OCA OCP Practice Question 3264

Question

Which one of the following class definitions will compile without any errors?

a) class P<T> {
       static T s_mem;
   }/*from   w  w w.  ja va 2 s .  c om*/

b) class Q<T> {
       T mem;
       public Q(T arg) {
               mem = arg;
       }
   }

c) class R<T> {
       T mem;
       public R() {
               mem = new T();
       }
   }

d) class S<T> {
       T []arr;
       public S() {
               arr = new T[10];
       }
   }


b)

Note

Option a): You cannot make a static reference of type T.

Option c) and d): You cannot instantiate the type T or T[] using new operator.




PreviousNext

Related