Given:
5. class Atom{
6. Atom(){System.out.print("atom ");}
7. }
8. class Rock extends Atom{
9. Rock(String type){System.out.print(type);}
10. }
11. public class Mountain extends Rock{
12. Mountain(){
13. super("granite ");
14. new Rock("granite ");
15. }
16. public static void main(String[] a){new Mountain();}
17. }
What is the result?
A. Compilation fails.
B. atom granite
C. granite granite
D. atom granite granite
E. An exception is thrown at runtime.
F. atom granite atom granite
答案:F
--------------------------------------------------------------------------
class Atom{
Atom(){System.out.print("atom ");}
}
class Rock extends Atom{
Rock(String type){System.out.print(type);}
}
public class Mountain extends Rock{
Mountain(){
super("granite ");
new Rock("granite ");
}
public static void main(String[] a){new Mountain();}
}
沒有留言:
張貼留言