已知: 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; 则:
举一反三
- 以下的类(接口)定义中正确的是( ) 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 base{public:virtual int f(int a)=0;......};class derived: public base{public:int f(int a,int b){return a*b;}......};
- 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方法。( )
- 已有如下程序: class Parent{ public int addValue(int a,int b){ return a+b ; } } public class Child extends Parent{ ..... } 下面那些方法可以添加到Child类中。 A: public int addValue(int a , int b){ .. } B: public void addValue( ){ .. } C: public int addValue( int a ){ .. } D: public void addValue( int a , int b){ .. }
- 请写出下列程序的输出结果。class A{public int f(int x) {return x+1;}}class B extends A{public int f(int x){return x*x;}}public class E{public static void main(String args[]){A a=new B();int m=a.f(10);System. out. println(m) ;}}