猿问

Java范型一问

Given:

2. public class Organic<E> {

3.     void react(E e) { }

4.     static void main(String[] args) {

5.         // Organic<? extends Organic> compound = new Aliphatic<Organic>();

6.         // Organic<? super Aliphatic> compound = new Aliphatic<Organic>();

7.         compound.react(new Organic());

8.         compound.react(new Aliphatic());

9.         compound.react(new Hexane());

10. } }

11. class Aliphatic<F> extends Organic<F> { }

12. class Hexane<G> extends Aliphatic<G> { }

 

Which, taken independently, are true? (Choose all that apply.)

A. If line 5 is uncommented, compilation fails due to an error at line 7.

B. If line 5 is uncommented, compilation fails due to an error at line 8.

C. If line 5 is uncommented, compilation fails due to an error at line 9.

D. If line 6 is uncommented, compilation fails due to an error at line 7.

E. If line 6 is uncommented, compilation fails due to an error at line 8.

F. If line 6 is uncommented, compilation fails due to an error at line 9.

 

答案是ABCD,求解释! 多谢


人到中年有点甜
浏览 402回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答