多选题class A {  A() { }  }  class B extends A {  }  Which two statements are true?()AClass B’s constructor is public.BClass B’s constructor has no arguments.CClass B’s constructor includes a call to this().DClass B’s constructor includes a call to super().

题目
多选题
class A {  A() { }  }  class B extends A {  }  Which two statements are true?()
A

Class B’s constructor is public.

B

Class B’s constructor has no arguments.

C

Class B’s constructor includes a call to this().

D

Class B’s constructor includes a call to super().

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

第1题:

有如下程序:includeusing namespace std;class test{private: int a;public: test(

有如下程序:#include<iostream>using namespace std;class test{private: int a;public: test(){cout<<"constructor"<<endl;} test(int a){cout<<a<<endl;} test(const test&_test) { a=_test.a; cout<<"copy constructor"<<en+dl; } ~test(){cout<<"destructor"<<endl;}};int main(){ test A(3); rerun 0;}运行时输出的结果是

A.3

B.constructor destructor

C.copy constructor destructor

D.3 destructor


正确答案:D
解析:本题考查的知识点是:构造函数和析构函数。一个类可以有多个构造函数,但只能有一个析构函数。每一个对象在被创建的时候,都会隐含调用众多构造函数中的一个,而在被销毁的时候,又会隐含调用唯一的那个析构函数。因此,解此类题目只要找准创建时调用的是哪个构造函数,和对象何时被销毁即可。本题只有主函数中创建了一个对象A,并使用了构造参数3,因此会隐含调用test(int a)这个构造函数,输出一个3。接下来主函数结束,对象A被销毁,所以又隐含调用~test()析构函数,输出一个destructor。故本题应该选择D。

第2题:

下列程序时类D代码段出现编译错误,原因是【 】。 include class A { public:A(char c)

下列程序时类D代码段出现编译错误,原因是【 】。

include<iostream. h>

class A

{

public:

A(char c){cout<<"A's constructor."<<c<<endl;}

~A(){cout<<"A's destructor."<<endl;}

};

class B: virtual public A

{

public:

B(char cb,char cd):A(cb) {cout<<"B's constructor."<<cd<<endl;}

~B(){cout<<"B's destructor."<<endl;}

private:

char b;

};

class C:virtual public A

{

public:

C(char cc, char cd):A(cc)

{cout<<"C's constructor. "<<cd<<endl;}

~C(){cout<<"C's destructor."<<endl;}

};

class D:public B,public C

{

public:

D(char cd,char ce,char cf, char cg, char ch,char ci)

:C(cf,cg),B(cd,ce),A(cd),aa(ch)

{cout<<"D's constructor."<<ci<<endl;}

~D() {cout<<"D's destructor."<<endl;}

private:

A aa;

};

void main()

{

D ohj('a','b','c','d','e','f')

}


正确答案:类的继承出现二义性
类的继承出现二义性 解析:本题就是通过实例来表现多继承时出现的二义性问题。多重继承比较复杂,尽管C++中提供了虚基类来解决这个问题,但在实际开发中由于过于复杂而往往尽量避免使用。

第3题:

What happens when you try to compile and run the following program?

class Mystery{String s;public static void main(String[] args){

Mystery m=new Mystery();m.go();}void Mystery(){s=”constructor”;}void go(){System.out.println(s);}

}()

A.this code will not compile

B.this code compliles but throws an exception at runtime

C.this code runs and “constructor” in the standard output

D.this code runs and writes “null” in the standard output


参考答案:D

第4题:

Which two statements are true regarding the creation of a default constructor?()   

  • A、 The default constructor initializes method variables.
  • B、 The default constructor invokes the no-parameter constructor of the superclass.
  • C、 The default constructor initializes the instance variables declared in the class.
  • D、 If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates a default constructor.
  • E、 The compiler creates a default constructor only when there are no other constructors for the class.

正确答案:C,E

第5题:

class A {  A() { }  }  class B extends A {  }  Which two statements are true?()

  • A、 Class B’s constructor is public.
  • B、 Class B’s constructor has no arguments.
  • C、 Class B’s constructor includes a call to this().
  • D、 Class B’s constructor includes a call to super().

正确答案:B,D

第6题:

关于constructor,下列描述正确的是()。

A.class中的constructor不可省略

B.constructor在一个对象被new时执行

C.一个class只能定义一个constructor

D.constructor必须与class同名,但方法不能与class同名


参考答案:B

第7题:

有如下程序: #inClude<iostream> using namespaCe std; Class test{ private: int a; publiC: test( ){Cout<<”ConstruCtor”<<endl;} test(int A.{Cout<<a<<endl;} test(Const test&_test){ a=test.a: Cout<<”Copy ConstruCtor”<<endl: } test( ){Cout<<”destruCtor”<<endl;} }; int main( ){ test A(3); return 0; } 执行这个程序的输出结果是( )。

A.3

B.ConstruCtor destruCtor

C.Copy ConstruCtor destruCtor

D.3 destruCtor


正确答案:D
本题考查默认构造函数和带参数的构造函数以及析构函数,本题中定义了一个对象A(3),对象带着参数,所以执行带参数的构造函数.输出3,然后执行析构溺数,输出destructor。所以本题答案为D。

第8题:

下列说法正确的有()

A.class中的constructor不可省略

B.constructor必须与class同名,但方法不能与class同名

C.constructor在一个对象被new时执行

D.一个class只能定义一个constructor


正确答案:C

第9题:

Which three statements are true?()

  • A、 The default constructor initializes method variables.
  • B、 The default constructor has the same access as its class.
  • C、 The default constructor invoked the no-arg constructor of the superclass.
  • D、 If a class lacks a no-arg constructor, the compiler always creates a default constructor. 
  • E、 The compiler creates a default constructor only when there are no other constructors for the class.

正确答案:B,C,E

第10题:

In which two cases does the compiler supply a default constructor for class A?()  

  • A、 class A{}
  • B、 class A { public A(){} }
  • C、 class A { public A(int x){} }
  • D、 class Z {} class A extends Z { void A(){} }

正确答案:A,D

更多相关问题