高等继续教育 / 面向对象程序设计
正确率:100%
【面向对象程序设计】模拟试题
给出下面程序输出结果。#include <iostream.h>class Base {private: int Y;public:Base(int y=0) {Y=y;cout<<"Base("<<y<<")\n";}~Base() {cout<<"~Base()\n";}void print() {cout <<Y<< "";} };class Derived:public Base{private: int Z;public:Derived (int y, int z):Base(y){ Z=z;cout<<"Derived("<<y<<","<<z<<")\n"; }~Derived() {cout<<"~Derived()\n";}void print() {Base::print(); cout<<Z<<endl; }};void main(){Derived d(10,20);d.print(); }
考题内容:
给出下面程序输出结果。#include <iostream.h> class Base {private: int Y; public: Base(int y=0) {Y=y;cout<<"Base("<<y<<")\n";}~Base() {cout<<"~Base()\n";}void print() {cout <<Y<< "";} }; class Derived:public Base {private: int Z; public: Derived (int y, int z):Base(y) { Z=z; cout<<"Derived("<<y<<","<<z<<")\n"; } ~Derived() {cout<<"~Derived()\n";} void print() {Base::print(); cout<<Z<<endl; } };void main() {Derived d(10,20); d.print(); }
给出下面程序输出结果。#include <iostream.h>class Base {private: int Y;public:Base(int y=0) {Y=y;cout<<"Base("<<y<<")\n";}~Base() {cout<<"~Base()\n";}void print() {cout <<Y<< "";} };class Derived:public Base{private: int Z;public:Derived (int y, int z):Base(y){ Z=z;cout<<"Derived("<<y<<","<<z<<")\n"; }~Derived() {cout<<"~Derived()\n";}void print() {Base::print(); cout<<Z<<endl; }};void main(){Derived d(10,20);d.print(); }
考题内容:
给出下面程序输出结果。#include <iostream.h> class Base {private: int Y; public: Base(int y=0) {Y=y;cout<<"Base("<<y<<")\n";}~Base() {cout<<"~Base()\n";}void print() {cout <<Y<< "";} }; class Derived:public Base {private: int Z; public: Derived (int y, int z):Base(y) { Z=z; cout<<"Derived("<<y<<","<<z<<")\n"; } ~Derived() {cout<<"~Derived()\n";} void print() {Base::print(); cout<<Z<<endl; } };void main() {Derived d(10,20); d.print(); }
参考答案:
佳题速递: