class Super {  public int getLenght( ) { return 4; }  }  pub

题目
单选题
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).

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

第1题:

有以下程序:includeusingnamespacestd;definePI3.14classPoint{private: intx,y;pub

有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a,int b,int c):Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<cl.area()<<endl; return 0; } 程序执行后的输出结果是

A.314

B.157

C.78.5

D.153.86


正确答案:A
解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径r和一个求圆面积的函数成员area。在主函数main中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10*10=314,即对象c1的函数成员area的返回值为314。

第2题:

若有以下程序:include using namespace std;class Base{ int x;protected: int y;pub

若有以下程序: #include <iostream> using namespace std; class Base { int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx ( ) { return x; } }; class Inherit : private Base { private: int m; public: int p; void setvalue(int a,int b,int c, int d) { setx(a) ; y=b; z=c; m=d; } void display() { cout<<getx ()<<", "<<y<<", "<<z<<", "<<m<<end1; } }; int main() { Inherit A; A.setvalue(1,2,3,4); A.display(); return 0; } 程序运行后的输出结果是( )。

A.1,2,3,4

B.产生语法错误

C.4,3,2,1

D.2,3,4,5


正确答案:A
解析:本题中,基类Base中的保护成员y和公有成员setx和getx,经过私有继承以后,称为派生类Inherit的私有成员,所以可以在派生类Inherit的函数成员中对它们进行访问。类Inherit中的函数成员setvalue和display都是公有成员,所以可以通过Inherit的对象对它们进行访问。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

第3题:

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

第4题:

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

第5题:

class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() 

  • A、 public int method1(int a, int b) { return 0; }
  • B、 private int method1(int a, int b) { return 0; }
  • C、 private int method1(int a, long b) { return 0; }
  • D、 public short method1(int a, int b) { return 0: }
  • E、 static protected int method1(int a, int b) { return 0; }

正确答案:A,C

第6题:

public class Something {

public int addOne(final int x) {

return ++x;

}

}

这个比较明显。


正确答案:

 

错。int x 被修饰成final,意味着x 不能在addOne method 中被修改。

第7题:

有以下程序:includeusing namespace std;Class A{public:A(){tout{("A"}};classB{pub

有以下程序: #include<iostream> using namespace std; Class A{ public: A(){tout{("A"} }; classB{public:B(){cout<<"B";>> classC:public A{ B b; public: C(){cout<<"C";} }; int main(){C obj;return 0;} 执行后的输出结果是( )。

A.CBA

B.BAC

C.ACB

D.ABC


正确答案:D
解析: 本题考查的是类的继承和派生。系统首先要通过派生类的构造函数调用基类的构造函数,对基类成员初始化,然后对派生类中的新增成员初始化。

第8题:

有如下程序:includeclass Base{protected:int i;public:int j;};class Derived:pub

有如下程序: #include<iostream.h> class Base { protected:int i; public:int j; }; class Derived:public Base { int m; public:int n; }; int main() { Derived d; d.i=0; //[1]d.j=0; //[2]d.m=0; //[3]d.n=0; //[4]return 0; } 其中主函数中有两个赋值语句有错,这两个错误的赋值语句是( )。

A.[1]和[2]

B.[1)和[3]

C.[2]和[3]

D.[2]和[4]


正确答案:B

第9题:

public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age && name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?() 

  • A、 return super.hashCode();
  • B、 return name.hashCode() + age * 7;
  • C、 return name.hashCode() + comment.hashCode() /2;
  • D、 return name.hashCode() + comment.hashCode() / 2 - age * 3;

正确答案:B

第10题:

Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  

  • A、The code will fail to compile.
  • B、The constructor in a that takes an int as an argument will never be called as a result of constructing an     object of class b or c.
  • C、Class c has three constructors.
  • D、Objects of class b cannot be constructed.
  • E、At most one of the constructors of each class is called as a result of constructing an object of class c.

正确答案:B,C

更多相关问题