又一道!!!
13
====1. package foo;
2.
3. public class Outer {
4. public static class Inner {
5. }
6. }Which statement is true? A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()” 这道题答案,大家回答吧!记住要说出你答案的理由呀!
13
====1. package foo;
2.
3. public class Outer {
4. public static class Inner {
5. }
6. }Which statement is true? A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()” 这道题答案,大家回答吧!记住要说出你答案的理由呀!
解决方案 »
- java自学视频分享,0基础到高手的蜕变,不看后悔~~~~
- static 类是如何分配内存的?
- 关于ScheduledThreadPoolExecutor的一点疑惑
- XMLStreamWriter.writeStartElement,命名空间的问题
- 关于scanner读写系统输入的问题
- jdbc connection自动提交的问题
- 我不知道用struts怎么实现默认选中用户上次选择的radio啊!
- 请高手告诉我 在哪里能找到OpenGl for java的资料!!
- 根据Applet传入的scoops变量值 的switch语句函数应该放哪里?
- 咋回事:SQL Server Driver for Jdbc ?
- 不知为何的问题…………
- 四舍五入的问题请指点!谢谢!
14
====1. public class Enclosingone{
2. public class Insideone{}
3. }
4. public class Inertest{
5. public static void main (String[] args){
6. Enclosingone eo= new Enclosingone();
7. //insert code here
8. }
9. } Which statement at line 7 constructs an instance of the inner class? A. InsideOnew ei= eo.new InsideOn();
B. Eo.InsideOne ei = eo.new InsideOne();
C. InsideOne ei = EnclosingOne.new InsideOne();
D. EnclosingOne.InsideOne ei = eo.new InsideOne();
我觉得答案应该是D;
A:静态内部类中没有指向所在外部类的引用,所以在创建静态内部类的时候不需要外部类的引用。
B:因为该内部类是Public的,所以可以在任何地方被访问(前提是通过import引入这个包)。
C:原因同B
D:可以直接通过new 静态内部类的构造方法来创建一个静态内部类的实例。
14题:答案是D
在创建普通内部类的实例的时候,要先创建其所在外部类的实例,然后通过外部类的实例来调用new 内部类的构造方法,这样才能创建内部类的实例(静态内部类除外)。
13.d错误 ,普通inner class 用 对象.innerclass,而static inner class用 类.innerclass
..只有在inner class 所在的outer class 内部,才能省略