有以下程序:
#include
using namespace std;
class Base{
public:
Base(int x=0) {cout<};
class Derived : public Base{
public:
Derived(int x=0) {cout<private:
Base val;
};
int main(){
Derived d(1);
return 0;
}
程序的输出结果是
#include
using namespace std;
class Base{
public:
Base(int x=0) {cout<
class Derived : public Base{
public:
Derived(int x=0) {cout<
Base val;
};
int main(){
Derived d(1);
return 0;
}
程序的输出结果是
举一反三
- 下面的程序段中虚函数被重新定义的方法正确吗?class base{public:virtual int f(int a)=0;......};class derived: public base{public:int f(int a,int b){return a*b;}......};
- 下面程序输出的结果是( )。 #include<iostream> using namespace std; class A int X; public: A(int x):x(++x) ~A()cout<<x; ; class B:public A int y; public: B(int y):A(y),y(y) ~B()cout<<y;; ; void main() B b(3); A: 34 B: 43 C: 33 D: 44
- 有如下程序: #include<iostream> using namespace std; class XX{ int x; public: XX(int XX=0):x(xx){} int getX(){return x;} }; class YY:public XX{ int y; public: YY(int xx,int yy):XX(xx),y(yy){} int getV(){return getX()+y;} }; int main(){ YY c(3,4); cout<<c.getV()+c.getX()<<endl; return 0; } 运行这个程序的输出结果是______。 A: 3 B: 4 C: 7 D: 10
- 如何能使程序调用Base类的构造方法输出"base constructor"; class Base{ Base(int i){ System.out.println("base constructor"); } Base(){ } } public class Sup extends Base{ public static void main(String argv[]){ Sup s= new Sup(); //One } Sup() { //Two } public void derived() { //Three } }
- 运行如下程序,结果为_____。#include <;iostream>;using namespace std;int main( ){int x =10; do { cout <;<; --x ; }while( !x ); return 0;}