有如下程序: ClassBase{ public: intdata; }; ClassDerived1:publicBase{}; ClassDerived2:protectedBase{}; intmain(){ Derived1d1; Derived2d2; d1.data=0;//① d2.data=0;//② return0; } 下列关于程序编译结果的描述中,正确的是( )。
A.①②皆无编译错误
B.①有编译错误,②无编译错误
C.①无编译错误,②有编译错误
D.①②皆有编译错误
第1题:
有如下程序: #include<iostream> using namespace std; class BASE{ public: ~BASE( ){cout<<"BASE";} }; class DERIVED:public BASE{ public: ~DERIVED( ){cout<<"DERIVED";} }; int main( ){DERIVED x;return 0;} 程序的输出结果是
A.BASE
B.DERIVED
C.BASEDERIVED
D.DERIVEDBASE
第2题:
有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)
A.XY
B.YX
C.X
D.Y
第3题:
有如下程序: Class Base{ publiC: int data; }; Class Derivedl:publiC Base{}; Class Derived2:proteCted Base{}; int main( ) { Derivedl dl; Derived2 d2; dl.data=0;//① d2.data=0;//② retum 0; } 下列关于程序编译结果的描述中,正确的是( )。
A.①②皆无编译错误
B.①有编译错误,②无编译错误
C.①无编译错误,②有编译错误
D.①②皆有编译错误
第4题:
若有以下程序:
include <iostream>
using namespace std;
class Base
{
public:
void who()
{
cout<<"class Base"<<end1;
}
};
class Derivedl : public Base
{
public:
void who()
{
cout<<"class Derivedl"<<end1;
}
};
class Derived2 : public Base
{
public:
void who()
{
cout<<"class Derived2"<<end1;
}
};
int main()
{
Base *p;
Derivedl obj1;
Derived2 obi2;
p=&obj 1;
p=&obj2;
p->who ( );
return 0;
}
则该程序运行后的输出结果是【 】。
第5题:
若有以下程序: #include<iostream> using namespace Std; Class Base {public: Base() {x=0;} int x;}; class Derivedl:virtua1 public Base {public: Derived1() {x=10;}}; class Derived2:virtual1 public Base {public: Derived2()
A.20
B.30
C.10
D.0