下面的程序段中虚函数被重新定义的方法正确吗?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 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; } 程序的输出结果是
- 已知: class A { public: int a; int b(); int f(); int f(int); int g(); }; class B { public: char f(); int g(); private: int a; int b(); }; class C:public A,public B { }; 设有:C *pc; 则:
- 有如下程序: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 ;}下列关于程序编译结果的描述中,正确的是()
- 以下的类(接口)定义中正确的是( ) A: public class A{ private int x; public getX(){ return x; }} B: public abstract class A{ private int x; public abstract int getX(); public int aMethod(){ return 0; }} C: public class A{ private int x; public abstract int getX();} D: public interface interfaceA{ private int x; public int getX(){ return x; }}
- class A { public int f(int x,int y) { return x+y; } } class B extends A { public int f(byte x,int y) { return x*y; } } 子类B的对象只能调用子类中的f方法。( )