Topic: 内部类与外部类的问题?

  Print this page

1.内部类与外部类的问题? Copy to clipboard
Posted by: chenyajun5
Posted on: 2004-12-21 17:05

Given:
1. public class Outer{
2. public void someOuterMethod() {
3. // Line 3
4. }
5. public class Inner{}
6. public static void main( String[]argv ) {
7. Outer o = new Outer();
8. // Line 8
9. }
10. }
Which instantiates an instance of Inner?
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8

2.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-12-21 17:11

没多想,觉得是B

3.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: zerol
Posted on: 2004-12-21 17:51

A is correct.

B is wrong because we shall get an Outer object to instance an Inner Object in a static method:

o. new Inner();

4.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: chenyajun5
Posted on: 2004-12-21 17:55

A是正确的。。

5.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: j2ee8000
Posted on: 2004-12-21 23:38

去看一下<THINK IN JAVA>里面有写啦,你给出的好像没有对的
正确的应该是:outclass.inner i=p.new inner();i内部类的对象名,p为外部类的对象名

6.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: j2ee8000
Posted on: 2004-12-21 23:42

刚才上面的话有点误,i内部类要创建的对象,p为外部类的对象,这样应该好明白一点!

7.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: prettyxx
Posted on: 2004-12-22 13:36

感觉和j2ee8000 一样

8.Re:内部类与外部类的问题? [Re: chenyajun5] Copy to clipboard
Posted by: sc
Posted on: 2004-12-22 17:13

在类的static method里面不能调用非static method.所以B是错的。而C,D中Inner前面的是包名,显然,Inner不属于这些个包,所以也是错的。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923