Given the code fragment:



What is the result?

A.

Super
Sub
Sub

B.

Contract
Contract
Super

C. Compilation fails at line n1
D. Compilation fails at line n2

題解

這題的ArrayList物件並沒有使用到泛型,因此ArrayList物件可以存入任意的Object物件。

物件的getClass方法會回傳物件實體所屬的類別。