有如下程序:
#include
using namespace std;
class Base
{
private:
void funl() const{cout<<"funl";}
protected:
void fun2() const{cout<<"fun2";}
public:
void fun3() const{cout<<"fun3";}
};
class Derived:protected Base
{
public:
void fun4() const{cout<<"fun4";}
};
int main()
{
Derived obj;
obj.funl(); // ①
obj.fun2(); // ②
obj.fun3(); // ③
obj.fun4(); // ④
return 0;
}
其中有语法错误的语句是
A . ①②③④
B . ①②③
C . ②③④
D . ①④
第1题:
有如下程序:#include <iostream>using namespace std;class Base{private: char c;public: Base(char n) :c(n){} ~Base() { cout<<c; } };class Derived: public Base{private: char c; public: Derived(char n):Base(n+1),c(n) {} ~Derived() { cout<<c; }};int main (){ Derived obj ('x'); return 0;}执行上面的程序净输出
A.xy
B.yx
C.x
D.y
第2题:
有如下程序:#include <iostream>using namespace std;class Base{private: char c;public: Base(char n):c(n){} ~Base() { cout<<c; }};class Derived: public Base{private: char c;public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; }};int main(){ Derived obj('x'); return 0; }执行上面的程序将输出( )。
A.xy
B.yx
C.x
D.y
第3题:
第4题:
有如下程序: #include<iostream> using namespace std; class Base { private: void funl()const {cout<<"funl";} protected: void fun2() const{cout<<"fun2";} public; void fun3() const {cout<<"fun3";} }; class Derived:protected Base { public; void fun4() const {cout<<"fun4";} }; int main() { Derived obj; obj.funl(); //① obj.fun2(); //② obj.fun3(); //③ obj.fun4(): //④ return 0; } 其中有语法错误的语句是
A.①②③④
B.①②③
C.②③④
D.①④
第5题:
有如下程序: #include<iostream> using namespace std; class Base { private: void funlconst{tout<<”funl”;} protected: void fun2const{tout<<”fun2”;} public: void fun3const{cout<<”fhll3”;} }; class Derived:protected Base { public: void fhn4const{cout<<”filn4”;} }; int main { Derived obj; obj.funl;//① obj.fun2;//② obj.furd;//③ obj.fun4;//④ return U: } 其中有语法错误的语句是( )。
A.①②③④
B.①②③
C.②③④
D.①④