中国大学MOOC: 如下所示的Test类的Java程序中,共有几个构造方法()。 public class Test{
private int x;
public Test(){}
public void Test(int i){
this.x=i;
}
public Test(String str){} }
private int x;
public Test(){}
public void Test(int i){
this.x=i;
}
public Test(String str){} }
举一反三
- 已有如下程序: public class Test{ public Test(int x,int y,int z){.....} } 下面哪些方法是合法的构造方法重载:( ) A: Test(){} B: int Test(){} C: Test(int x,int y,byte z){} D: void Test(int x,int y,int z){}
- 以下是"public static void test(int x, int y)"的方法重载( ) A: public static void Test(int x) B: public static int test(int x, int y) C: public static void test(int y, int x) D: public static void test(int x, int y)
- 下列代码的执行结果是 。public class Test {public int aMethod(){static int i=0;i++;System.out.println(i);}public static void main(String args[ ]){Test test = new Test();test.aMethod();}}
- 2、class Test{ Test(){} } 下列构造方法中,哪个构造方法可以存在上述Test类中?( ) A: public Test(){}; B: private Test(){}; C: Test(int age){}; D: public Test(){};
- 有如下代码,则该程序运行时输出结果是。 class Test{ static int i=0; public void show() { i++; System.out.println(i); } } public class Demo { public static void main(String[] args) { Test test=new Test(); test.show(); } }