• 2021-04-14
    阅读以下程序,写出运行结果。
    #include
    using namespace std;
    class Test
    {
    private:
    int num;
    public:
    Test();
    Test(int n);
    };
    Test::Test()
    {
    cout << "Init defa" << endl;
    num = 0;
    }
    Test::Test(int n)
    {
    cout << "Init" << " " << n << endl;
    num = n;
    }


    int main()
    {
    Test x[2];
    Test y(15);
    return 0;
    }
  • Init defa
    Init defa Init 15

    内容

    • 0

      以下是"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)

    • 1

      给出下面代码段 1) public class Test { 2) int m, n; 3) public Test() {} 4) public Test(int a) { m=a; } 5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=0; k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) } 哪行将引起一个编译时错误?

    • 2

      下列代码中,将引起一个编译错误的行是______。 1)public class Test{ 2) int m,n; 3) public Test(){} 4) public Test(int a){m=a;} 5) public static void main(String args[]){ 6) Test t1,t2; 7) int j,k; 8) j=0;k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) }

    • 3

      (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); } }

    • 4

      抽象类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()); } } 关于上述代码说明正确的是_________