单选题1.public class Test{ 2.int x=12; 3.public void method(intx){ 4.x+=x; 5.System.out.println(x); 6.} 7.} Given: 34.Test t=new Test(); 35.t.method(5); What is the output from line 5 of the Test class?()A 5B 10C 12D 17E 24

题目
单选题
1.public class Test{ 2.int x=12; 3.public void method(intx){ 4.x+=x; 5.System.out.println(x); 6.} 7.} Given: 34.Test t=new Test(); 35.t.method(5); What is the output from line 5 of the Test class?()
A

5

B

10

C

12

D

17

E

24


相似考题
更多“1.public class Test{ 2.int x=12; 3.public void method(intx){”相关问题
  • 第1题:

    public class Test{2.int x=12;3.public void method(intx){4.x+=x;5.System.out.println(x);6.}7.}Given:34.Test t=new Test();35.t.method(5);What is the output from line 5 of the Test class?()

    A.5

    B.10

    C.12

    D.17

    E.24


    参考答案:B

  • 第2题:

    执行下列代码后,输出的结果为( )。 class Base { int x = 30; void setX( ) {x=1O;} } class SubClass extends Base { int x=40; void setX ( ) {x=20;} int getX( ) {return super. x; } } public class Test { public static void main(String[ ] args) { SubClass sub=new SubClass( ); sub. setX( ); System. out. println(sub, getX( ) ); } }

    A.10

    B.20

    C.30

    D.40


    正确答案:C
    解析:本题主要考查有关类的继承方面的知识。Java中,类是分层次的,当子类的成员变量与父类的成员变量名字相同时,子类的成员变量会隐藏父类的成员变量,当子类的成员方法与父类的成员方法名字、参数列表、返回值类型都相同时,子类的方法是父类的方法的重写。这样,在子类的对象调用方法时,是按照子类中方法定义执行,隐藏父类的方法的定义。当子类隐藏了父类的变量,并重写了父类的方法后,又要使用父类变量或父类被重写的方法时,可通过super来实现对父类变量的访问和父类方法的调用。因此,本题中在main ()中调用setX ()时,是调用的SubClass类中的setX ()函数,同时将SubClass类中的i变量值设为20。当main ()函数中调用getX ()函数时,并不是取了SubClass类中的i的值,而是取的Base类中i变量的值,此时i的值为其初始值30。

  • 第3题:

    执行下面程序,显示的结果为( )。 public class Test { public static void main (String args[]) { Test t=newTest(); System.out.println (Loverload ("2","3")); } int overload (intx,int y) {return x+y;} String overload (String x,Stnng y){return x+y;} }

    A.2

    B.3

    C.5

    D.23


    正确答案:D
    解析:本题考查方法重载相关知识。方法的重载是指多个方法可以享用相同的名字,但参数的数量或类型必须不完全相同、即方法体有昕不同。使用该方法时,编译系统会根据实参类型选择执行相应的方法。本题中,在调用overload()方法时,实参为字符串,因此会调用String overload (String x,String y)方法,该方法返回两实参连接后的结果,所以返回值为“23”。

  • 第4题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第5题:

    以下代码的输出结果?public class Test{int x=5;public static void main(String argv[]){Test t=new Test();t.x++;change(t);System.out.println(t.x);}static void change(Test m){m.x+=2;}}

    A. 7

    B. 6

    C. 5

    D. 8


    正确答案:D

  • 第6题:

    包pack1的类c_ass1中有成员方法:protected void method_1(){…},private void method_2(){…},public void method_3(){…}和 void method_4(){…},在包pack2中的类class2是class1的子类,它在class2中可以调用方法()。 

    • A、method_1
    • B、method_2
    • C、method_3
    • D、method_4

    正确答案:A,C,D

  • 第7题:

    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?() 

    • A、 x = 0
    • B、 x = 42
    • C、 Compilation fails because of an error in line 2 of class Test2.
    • D、 Compilation fails because of an error in line 3 of class Test1.
    • E、 Compilation fails because of an error in line 4 of class Test2.

    正确答案:C

  • 第8题:

    abstract class A {  abstract void al();  void a2() { }  }  class B extends A {  void a1() { }  void a2() { }  }  class C extends B { void c1() { } }  and:  A x = new B(); C y = new C(); A z = new C();  Which four are valid examples of polymorphic method calls?()

    • A、 x.a2();
    • B、 z.a2();
    • C、 z.c1();
    • D、 z.a1();
    • E、 y.c1();
    • F、 x.a1();

    正确答案:A,B,D,F

  • 第9题:

    public class Test {} What is the prototype of the default constructor?()  

    • A、 Test()
    • B、 Test(void)
    • C、 public Test()
    • D、 public Test(void)
    • E、 public void Test()

    正确答案:C

  • 第10题:

    单选题
    在Java语言中,包pack1的类class1中有成员方法:  protected void  method_1(){„},  private void method_2() {„},  public void method_3() {„}  和  void method_4() {„},  在包pack2中的类class2不是class1的子类,你在class2中可以调用方法()。
    A

    method_1

    B

    method_2

    C

    method_3

    D

    method_4


    正确答案: C
    解析: 暂无解析

  • 第11题:

    多选题
    包pack1的类class1中有成员方法: protected void method_1(){„}, private void method_2() {„},  public void method_3() {„}  和  void method_4() {„},  在包pack2中的类class2是class1的子类,你在class2中可以调用方法()。
    A

    method_1

    B

    method_2

    C

    method_3

    D

    method_4


    正确答案: C,D
    解析: 暂无解析

  • 第12题:

    单选题
    Consider the following class:     class Test(int i) {     void test(int i) {  System.out.println(“I am an int.”); }    void test(String s) {   System.out.println(“I am a string.”);     }          public static void main(String args) {    Test t=new Test();     char ch=“y”;    t.test(ch);     }      }     Which of the statements below is true?()
    A

     Line 5 will not compile, because void methods cannot be overridden.

    B

     Line 12 will not compile, because there is no version of test() that rakes a charargument.

    C

     The code will compile but will throw an exception at line 12.

    D

     The code will compile and produce the following output: I am an int.

    E

     The code will compile and produce the following output: I am a String.


    正确答案: A
    解析: 在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。

  • 第13题:

    完成下列类的构造函数,初始化语句为______。 include class Test { private: int x,y

    完成下列类的构造函数,初始化语句为______。

    include<iostream.h>

    class Test

    {

    private:

    int x,y;

    public:

    void Test(int initx,int inity){

    ______

    }

    void printx( ){cout<<x<<"-"<<y<<"="<<x-y;}

    };

    void main( )

    {

    Test x(300,200);

    x.printx( );

    }


    正确答案:x=initx; y=inity;
    x=initx; y=inity; 解析:本题考查的是类的私有数据如何从接口成员函数那里得到数据的。本题虽然简单,却体现了类的数据封装思想,并指明了如何完成这种封装。

  • 第14题:

    阅读下列代码段,选出该代码段的正确的文件名( )。 class A { void method () { System.out.println ("methodl in class A"); } } public class B { void method2 () { System.out.println("method2 in class B"); } public static void main (String args[]) { System.out.println ("main () in class B"); } }

    A.A.java

    B.A.class

    C.B.class

    D.B.java


    正确答案:D
    解析:Java源文件以.java为后缀,Java字节码文件以.class为后缀。Java源文件中只有一个public的类,该类的名字为源文件名,这里类B是以public修饰的,因此源文件名为B.java。

  • 第15题:

    有以下程序: include class A { intx; public: A(int a) { x=a;} friend class B;

    有以下程序:

    include<iostream.h>

    class A

    {

    int x;

    public:

    A(int a)

    {

    x=a;

    }

    friend class B;

    }

    class B{

    public:

    void print(A a){

    a. x--;

    cout<<a.x<<end1;

    }

    };

    void main()

    {

    A a(10);

    B b;

    b.print(a) ;

    }

    程序执行后的输出结果是【 】。


    正确答案:9
    9 解析:本题考核友元类的应用。在程序中,类B是类A的友元类,因此,在类B的所有成员函数中均可访问类A的任何成员。在main()中,先定义类A的一个对象a(10)和类B的一个对象b。然后通过对象b调用其成员函数print输出对象a的私有成员x的值减1即9。

  • 第16题:

    以下代码的输出结果?public class Test{int x=3;public static void main(String argv[]){int x= 012;System.out.println(x);}}

    A.12

    B.012

    C.10

    D.3


    正确答案:C

  • 第17题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第18题:

    在Java语言中,包pack1的类class1中有成员方法:  protected void  method_1(){„},  private void method_2() {„},  public void method_3() {„}  和  void method_4() {„},  在包pack2中的类class2不是class1的子类,你在class2中可以调用方法()。 

    • A、method_1
    • B、method_2
    • C、method_3
    • D、method_4

    正确答案:C

  • 第19题:

    包pack1的类class1中有成员方法: protected void method_1(){„}, private void method_2() {„},  public void method_3() {„}  和  void method_4() {„},  在包pack2中的类class2是class1的子类,你在class2中可以调用方法()。 

    • A、method_1
    • B、method_2
    • C、method_3
    • D、method_4

    正确答案:A,C

  • 第20题:

    1. public class Test {  2. int x= 12;  3. public void method(int x) {  4. x+=x;  5. System.out.println(x);  6. }  7. }  Given:  34. Test t = new Test();  35. t.method(5);  What is the output from line 5 of the Test class?() 

    • A、 5
    • B、 10
    • C、 12
    • D、 17
    • E、 24

    正确答案:B

  • 第21题:

    单选题
    1. public class Test {  2. int x= 12;  3. public void method(int x) {  4. x+=x;  5. System.out.println(x);  6. }  7. }  Given:  34. Test t = new Test();  35. t.method(5);  What is the output from line 5 of the Test class?()
    A

     5

    B

     10

    C

     12

    D

     17

    E

     24


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?()
    A

     x = 0

    B

     x = 42

    C

     Compilation fails because of an error in line 2 of class Test2.

    D

     Compilation fails because of an error in line 3 of class Test1.

    E

     Compilation fails because of an error in line 4 of class Test2.


    正确答案: E
    解析: 暂无解析

  • 第23题:

    单选题
    1.public class Test{ 2.int x=12; 3.public void method(intx){ 4.x+=x; 5.System.out.println(x); 6.} 7.} Given: 34.Test t=new Test(); 35.t.method(5); What is the output from line 5 of the Test class?()
    A

    5

    B

    10

    C

    12

    D

    17

    E

    24


    正确答案: D
    解析: 暂无解析

  • 第24题:

    单选题
    public class Test {} What is the prototype of the default constructor?()
    A

     Test()

    B

     Test(void)

    C

     public Test()

    D

     public Test(void)

    E

     public void Test()


    正确答案: D
    解析: The correct answer to this question is C. The default constructor always takes the same access of the class. In this case, the class is public and so does the default constructor.