• 2022-05-29
    设有泛型类的定义如下class Test { }则由该类创建对象时,使用正确的是?
    A: Test x = new Test();数据添加到文件中;
    B: Test x = new Test();
    C: Test x = new Test();
    D: Test x = new Test();
    C

    内容

    • 0

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

    • 1

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

    • 2

      给出如下类定义: public class Test { Test(int i) { } } 如果要创建一个该类的对象,正确的语句是( )。 A: Test t = newTest(); B: Test t = newTest(5); C: Test t = newTest("5"); D: Test t = newTest(3.4);

    • 3

      下列程序的输出结果是 _____ 。 #include using namespace std; class Test { public: Test() { cnt++; } ~Test() {cnt--; } static int Count() { returncnt;} private: static int cnt; }; int Test::cnt = 0; int main() { cout << Test::Count()<<' '; Test tl, t2; Test* pT3 = new Test; Test* pT4 = new Test; cout << Test::Count()<<' '; delete pT4; delete pT3; cout << Test::Count()<< endl; return 0; }

    • 4

      以下程序运行结果是?public class Test{int value;public static void main(String args&#91;&#93;) {Test t=new Test();if(t==null) {System.out.println("No Object");}else {System.out.println(t.value);}}} A: 0 B: C: NoObject D: 编译错误