(6-2)定义如下Base类,能在(1)处正确调用Base的构造方法。
class Base{
int x,y;
Base(int x){}
Base(int x,int y){
//(1)调用Base的构造方法
}
}
class Base{
int x,y;
Base(int x){}
Base(int x,int y){
//(1)调用Base的构造方法
}
}
举一反三
- 给出下面的代码段 public class Base{ int x, y; static int z; public Base(int a,int b)<br/>{ x=a; y=b; } } 以下代码错误的是?(). A: Base b=new Base(); <br/>b.z=10; B: Base b=new Base(1,2); <br/>b.z=10; C: Base.z=10; D: Base b=new Base(1,2);<br/>b.x=2;
- 有以下程序: #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; } 程序的输出结果是
- 如何能使程序调用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 } }
- 定义如下类Base,是setNum()方法的重载方法。 class Base{ public void setNum (int a,int b,float c){ } }
- 定义如下类Base,是setNum()方法的重载方法。class Base{...,int b,float c){ }}