单选题Given:  Which code, inserted at line 15, creates an instance of the Point class defined in Line?()A  Line l = new Line() ; l.Point p = new l.Point();B  Line.Point p = new Line.Point();C  The Point class cannot be instatiated at line 15.D  Point p =

题目
单选题
Given:  Which code, inserted at line 15, creates an instance of the Point class defined in Line?()
A

 Line l = new Line() ; l.Point p = new l.Point();

B

 Line.Point p = new Line.Point();

C

 The Point class cannot be instatiated at line 15.

D

 Point p = new Point();

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Click the Exhibit button. Given:Which two statements are true if a NullPointerException is thrown on line 3 of class C? ()

A.The application will crash.

B.The code on line 29 will be executed.

C.The code on line 5 of class A will execute.

D.The code on line 5 of class B will execute.

E.The exception will be propagated back to line 27.


参考答案:B, E

第2题:

Given:Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()

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

第3题:

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。

【说明】Point是平面坐标系上的点类,Line是从Point派生出来的直线类。

include <iostream.h>

class Point

{public:

Point (int x, int y) ;

Point (Point &p) ;

~Point();

void set (double x, double y) ;

void print();

private:double X,Y;

};

Point::Point (int x, int y) //Point 构造函数

{X=x; Y=y; }

Point::Point ( (1) ) //Point 拷贝构造函数

{X=p.X; Y=p.Y;}

void Point::set (double x, double y)

{X=x; Y=y; }

void Point::print()

{cout<<' ('<<X<<","<<Y<<") "<<endl; }

Point::~Point()

{cout<<"Point 的析构函数被调用! "<<endl;

class Line: public Point

{public:

Line (int x, int y, int k) ;

Line (Line &s) ;

~Line();

void set (double x, double y, double k)

void print();

private:double K;

};

(2)//Line 构造函数实现

{ K=k;}

(3)//Line 拷贝构造函数实现

{K=s.K;}

void Line::set (double x, double y, double k)

{ (4);

K=k;

}

void Line::print()

{cout<<" 直线经过点";

(5);

cout<<"斜率为: k="<<K<<endl;

}

Line: :~Line()

{cout<<"Line 析构函数被调用! "<<endl;

}

void main()

{Line 11 (1,1,2) ;

11 .print();

Linel2 (11) ;

12.set (3,2,1) ;

12.print();

}


正确答案:(1)Point &p (2)Linc::Line(int xint y int k):Point(xy) (3)Line::Line(Line &s):Point(s) (4)Point::set(x y) (5)Point::print()
(1)Point &p (2)Linc::Line(int x,int y, int k):Point(x,y) (3)Line::Line(Line &s):Point(s) (4)Point::set(x, y) (5)Point::print() 解析:(1)Point &p
Point拷贝构造函数的形参必须是Point对象的引用。
(2)Linc::Line(int x,int y, int k):Point(x,y)
Line的构造函数必须先调用Point构造函数构造Line的基类Point。
(3)Line::Line(Line &s):Point(s)
Line的拷贝构造函数必须先调用Point拷贝构造函数来构造并复制Line对象的基类 Point部分。
(4)Point::set(x, y)
Line的set成员函数必须通过Point的set成员函数才能访问基类的私有成员。而且在 set名前必须加成员名限定Point::,以区别Line的set函数。
(5)Point::print()
Line的print成员函数必须通过Point的print成员函数才能访问打印基类的私有成员。而且在print名前必须加成员名限定Point::,以区别Line的print函数。

第4题:

Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?() 

  • A、 The declaration on line 2 does not allocate memory space for the variable myVect.
  • B、 The declaration on line 2 allocates memory space for a reference to a Vector object.
  • C、 The statement on line 2 creates an object of class Vector.
  • D、 The statement on line 3 creates an object of class Vector.
  • E、 The statement on line 3 allocates memory space for an object of class Vector.

正确答案:A,D,E

第5题:

class Super {  public int getLenght( ) { return 4; }  }  public class Sub extends Super {  public long getLenght( ) { return 5; }  public static void main(String[] args) {  Super sooper = new Super( );  Sub sub = new Sub( );  System.out.println(  sooper.getLenght( ) + “,” + sub.getLenght( ) );  }  } What is the output?()

  • A、 Just after line 13.
  • B、 Just after line 14.
  • C、 Just after line 15.
  • D、 Just after line 16 (that is, as the method returns).

正确答案:C

第6题:

Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C

第7题:

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

正确答案:A

第8题:

Given:Which code, inserted at line 15, creates an instance of the Point class defined in Line?()

A.Point p = new Point();

B.Line.Point p = new Line.Point();

C.The Point class cannot be instatiated at line 15.

D.Line l = new Line() ; l.Point p = new l.Point();


参考答案:B

第9题:

10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() 

  • A、 Point p = new Point();
  • B、 Line.Point p = new Line.Point();
  • C、 The Point class cannot be instatiated at line 15.
  • D、 Line 1 = new Line() ; 1.Point p = new 1.Point();

正确答案:B

第10题:

Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()   

  • A、 line 3
  • B、 line 6
  • C、 line 7
  • D、 line 8
  • E、 line 10

正确答案:D

更多相关问题