• 2021-04-14
    中国大学MOOC: 如下所示的Test类的Java程序中,共有几个构造方法()。 public class Test{
    private int x;
    public Test(){}
    public void Test(int i){

    this.x=i;
    }
    public Test(String str){} }
  • 2

    内容

    • 0

      (6-6)请阅读程序,写出程序运行结果。 class Test{ static int x=10; int y=99; { y=y+10; } static { x=x+5; } { y=y+10; } static { x=x+5; } public Test() {//构造方法 x=x+5; } { System.out.println(x*y); } } public class Demo11 { public static void main(String[] args) { Test t1=new Test(); Test t2=new Test(); } }

    • 1

      (06-03)在Java中,以下程序编译运行后的输出结果为( )。 public class Test { int x, y; Test(int x, int y) { this.x = x; this.y = y; } public static void main(String[] args) { Test pt1, pt2; pt1 = new Test(3, 3); pt2 = new Test(4, 4); System.out.print(pt1.x + pt2.x); } }

    • 2

      抽象类A和抽象类Test的定义如下: abstract class A { abstract int getInfo() { } } public class Test extends A { private int a = 0; public int getInfo() { return a; } public static void main(String args[]) { Test b= new Test(); System.out.println(b.getInfo()); } } 关于上述代码说明正确的是_________

    • 3

      阅读程序 public class Test{ int x=12; public void method1(int x){ x+=x; System.out.println(x); } } 如果有如下的代码段: Test t=new Test(); t.method1(5); 程序执行到这个地方,代码输出结果是__________?

    • 4

      (06-06)分析如下所示的Java代码,其中this关键字的意思是( )。 public class Test { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; //this关键字所在的行 } } Class Main{ Public static void main(String []args){ Test T1 = new Test(); T1.setname(“zhangsan”); } }