(单选题)下面程序中,第16行可以插入的正确代码是()
1
10. class Line {
2
11. public class Point { public int x,y;}
3
12. public Point getPoint() { return new Point(); }
4
13. }
5
14. class Triangle {
6
15. public Triangle() {
7
16. // insert code here
8
17. }
9
18. }
A.Point p = Line.getPoint();
B.Line.Point p = Line.getPoint();
C.Point p = (new Line()).getPoint();
D.Line.Point p = (new Line()).getPoint();
正确答案:D
解析:知识点: 创建实例内部类的实例时,外部类的实例必须存在 外部类类名.内部类类名引用变量名称= 外部类对象的引用.new 内部类构造器; 外部类类名.内部类类名引用变量名称= new 外部类构造器.new 内部类构造器;
(单选题)请看如下代码,对Inner实例化描述正确的是()
01
public class Outer{
02
public void someOuterMethod() {
03
// Line 3
04
}
05
public class Inner{}
06
public static void main(String[] args) {
07
Outer o = new Outer();
08
// Line 8
09
}
10
}
A.new Inner(); // At line 3
B.new Inner().Outer(); // At line 8
C.new o.Inner(); // At line 8
D.new Outer.Inner(); // At line 8
正确答案:A
解析:考察内部类 成员内部类中可以直接用内部类创建对象 A对。在外部类里面创建成员内部类的实例: this.new Innerclass(); 在外部类之外创建内部类的实例: (new Outerclass()).new Innerclass(); 在内部类里访问外部类的成员: Outerclass.this.member
1
10. class Line {
2
11. public class Point { public int x,y;}
3
12. public Point getPoint() { return new Point(); }
4
13. }
5
14. class Triangle {
6
15. public Triangle() {
7
16. // insert code here
8
17. }
9
18. }
A.Point p = Line.getPoint();
B.Line.Point p = Line.getPoint();
C.Point p = (new Line()).getPoint();
D.Line.Point p = (new Line()).getPoint();
正确答案:D
解析:知识点: 创建实例内部类的实例时,外部类的实例必须存在 外部类类名.内部类类名引用变量名称= 外部类对象的引用.new 内部类构造器; 外部类类名.内部类类名引用变量名称= new 外部类构造器.new 内部类构造器;
(单选题)请看如下代码,对Inner实例化描述正确的是()
01
public class Outer{
02
public void someOuterMethod() {
03
// Line 3
04
}
05
public class Inner{}
06
public static void main(String[] args) {
07
Outer o = new Outer();
08
// Line 8
09
}
10
}
A.new Inner(); // At line 3
B.new Inner().Outer(); // At line 8
C.new o.Inner(); // At line 8
D.new Outer.Inner(); // At line 8
正确答案:A
解析:考察内部类 成员内部类中可以直接用内部类创建对象 A对。在外部类里面创建成员内部类的实例: this.new Innerclass(); 在外部类之外创建内部类的实例: (new Outerclass()).new Innerclass(); 在内部类里访问外部类的成员: Outerclass.this.member