Consider the following code snippet: Assume that the method call to print(makeAr
ID: 3708349 • Letter: C
Question
Consider the following code snippet:
Assume that the method call to print(makeArray(a)) works correctly by printing the int array a. Which of the following headers for the makeArray method will make this possible?
I public static Integer[] makeArray(int[] a)
II public static E[] makeArray(int[] a)
III public static Integer[] makeArray(E[] a)
What does it mean when the syntax ? extends D is used?
Consider the following code snippet that declares the GraduateStudent class:
Which of these statements are false?
I GraduateStudent is a subclass of Student
II Stack<GraduateStudent> is a subclass of Stack<Student>
III Stack<Student> is a subclass of Stack<GraduateStudent>
Which of the following necessitates the type erasure process?
I The Java virtual machine does not work with generic types
II To maintain backward compatibility to older versions of Java
III Generics do not work with primitives
I and III only
Which of the following are restrictions of Java generic programming?
I You cannot use the assignment operator = to assign one generic object to another.
II You cannot use the == operator to compare two generic objects.
III You cannot construct arrays of generic types.
I and III onlyExplanation / Answer
Explanation: - Generic methods does not work with static keywords. As the class definition of option II and option III should be declared in generic class. But both methods are using static declaration. As static methods cannot be used in generic class, So, option II and option III are wrong. Hence B is the answer.
2. a) Any subclass of D may be used.
Explanation: - ? extends D means either D or any subclass of D can be used . super class of D cannot be used. So option 1 is correct.
3. C) II and III only
Explanation: - The statement only tells that GraduateStudent is child class of Student class. There is nothing mentioned about Stack. So c) is correct
4. B) I and II only
Explanation: - Generics not working with primitives is not necessary for erasure process.
5. D) III only
Explanation: - Arrays cannot be created using generic type. ‘=’ can be used to assign one generic object to another.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.