Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 127

Given the code fragment:

You have been asked to define the ProductCode class. The definition of the ProductCode class must allow c1 instantiation to succeed and cause a compilation error on c2 instantiation.

Which definition of ProductCode meets the requirement?

A.

B.

C.

D.

    Correct Answer:

    The correct answer is B. Option B defines the ProductCode class with a generic type parameter S that extends T, which means S must be a subtype of T. In this context, T is Number and S is Integer for c1, which complies with the constraint. However, for c2, T is Number and S is String, and since String does not extend Number, this will result in a compilation error. Therefore, it satisfies both conditions: allowing c1 instantiation and causing a compilation error on c2 instantiation.

Discussion
Svetleto13

B,tested

asdfjhfgjuaDCV

b is correct

steefaand

B is correct, tested.

duydn

B is correct: String not extend from Number -> make c2 compilation error

Ohayou

Answer B