有如下程序:class Base {public :int date ;} ;class Derived1 : public Base { };class Derived2 : protected Base { };int main(){Derived1 d1 ;Derived2 d2 ;d1. date = 0 ; //①d2.date = 0 ; //②return 0 ;}下列关于程序编译结果的描述中,正确的是()
举一反三
- 有以下程序: #include <iostream> using namespace std; class Base{ public: Base(int x=0) {cout<<x;} }; class Derived : public Base{ public: Derived(int x=0) {cout<<x;} private: Base val; }; int main(){ Derived d(1); return 0; } 程序的输出结果是
- 写出下面程序的运行结果。 #include <iostream> using namespace std; class Base { public: void Who( ){cout<<"class Base"<<endl;} }; class Derived1:public Base { public: void Who( ){cout<<"class Derived1"<<endl;} }; class Derived2:public Base { public: void Who( ){cout<<"class Derived2"<<endl;} }; int main( ) { Base obj1,*p; Derived1 obj2; Derived2 obj3; p=& obj1; p->Who(); p=& obj2; p->Who(); p=& obj3; p->Who(); obj2.Who(); obj3.Who(); 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;}......};
- 如何能使程序调用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 } }
- (6-2)以下代码会出现编译错误。 class Base{ public Base () { System.out.println("1"); } public void Base () { System.out.println("2"); } }