又一道!!!
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()” 这道题答案,大家回答吧!记住要说出你答案的理由呀!
解决方案 »
- junit测试需要测试main函数吗
- java 关于解压rar文件 代码有点问题 帮改正--请进
- 问一个极其傻瓜的问题
- 如何将一个xsd变成java的一个class
- !!!关于字符串的连接问题!!!!!!!!!!!!!!!
- 高手请进,如何得到注册在当前机器上的所有数据源?
- My team leader is so excellent and handsome!!!
- 在一个类中this.filled = 12312312;filled= 12312312;有什么区别
- Applet中调用Corba,需要使用org.omg.CORBA.ORB.class。但是IE找不到这个类所在的Jar。
- 请告诉JAVA得字符串中如何表示回车符!
- 不知为何的问题…………
- 四舍五入的问题请指点!谢谢!
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 内部,才能省略