现有:  public class Tester {  public static void main (String[] args)  {      intx-5;  Integer xl=x;  Integer x2=x;     int x3=new Integer(5);  system..ut.print(x1.equals(x));      system..ut.print(xl==x);  system..ut.print(x2.equals(xl));      system..ut.p

题目

现有:  public class Tester {  public static void main (String[] args)  {      intx-5;  Integer xl=x;  Integer x2=x;     int x3=new Integer(5);  system..ut.print(x1.equals(x));      system..ut.print(xl==x);  system..ut.print(x2.equals(xl));      system..ut.print(x2==xl);      system..ut.print(x2==x3);  system..ut.print(x2.equals(x3));         }      }      结果为:()     

  • A、编译失败
  • B、falsefalsetruetruetruetrue
  • C、truetruetruetruetruetrue
  • D、falsefalsetruetruetruefalse
  • E、truefalsetruefalsefalsetrue
  • F、运行时异常被抛出
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

若有以下程序:include using namespaces std;class A{public: A (){} A (int i) {x1=

若有以下程序: #include <iostream> using namespaces std; class A { public: A (){} A (int i) { x1=i; } void dispa() { cout<<"xl="<<xl<<" , "; } private: int x1; }; class B : public A { public: B (){} B (int i):A(i+10) { x2=i; } void dispb() { dispa (); cout <<"x2="<<x2<<end1; } private: int x2; }; int main () { B b(2); b.dispb (): return 0; } 程序运行后的输出结果是( )。

A.x1=10,x2=2

B.x1=12,x2=10

C.x1=12,x2=2

D.x1=2,x2=2


正确答案:C
解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数宋初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数,使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对子对象初始化的构造函数。本题中,在派生类B的构造函数中,调用基类A的构造函数对基类A的数据成员x1进行了初始化。

第2题:

以下程序的运行结果为:public class A {static int k=3;public static void main(String[] args) {int k=4;A x1=new A();x1.k++;A x2=new A();x2.k++;k++;System.out.println(x1.k);}}

A. 3

B. 4

C.5

D.6

E.7


正确答案:C

第3题:

现有:publicclassTester{publicstaticvoidmain(String[]args){intx-5;Integerxl=x;Integerx2=x;intx3=newInteger(5);system..ut.print(x1.equals(x));system..ut.print(xl==x);system..ut.print(x2.equals(xl));system..ut.print(x2==xl);system..ut.print(x2==x3);system..ut.print(x2.equals(x3));}}结果为:()

A.编译失败

B.falsefalsetruetruetruetrue

C.truetruetruetruetruetrue

D.falsefalsetruetruetruefalse

E.truefalsetruefalsefalsetrue

F.运行时异常被抛出


参考答案:C

第4题:

程序: class TestApp{ public static void main (String[] args){ int x=6; if (x>l) System. out. println("x>l"); else if (x>5) System. out .println("x>5"); else if (x<10) System. out. println("x

  • A、x>5
  • B、x>l
  • C、x<10
  • D、x<29

正确答案:B

第5题:

class Beta {  public static void main(String [] args) {  Integer x = new Integer(6) * 7;  if (x != 42) {  System.out.print("42 ");  } else if (x 〈 new Integer(44-1)) {  System.out.println("less");  } else {  System.out.print("done"); } } }  结果是什么?() 

  • A、less
  • B、42
  • C、done
  • D、编译失败

正确答案:A

第6题:

下列程序段执行后,x5的结果是______。 public class ex42 { public static void main(String[] args) { int xl = 8; int x2 = 12; int x3=7; int x4; int x5; x4 = x1 > x2 ? x1 : x2+ x1; x5 = x4 > x3 ? x4 : x3; System.out.println(x5); } }

A.11

B.20

C.10

D.12


正确答案:B

第7题:

public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? () 

  • A、 0
  • B、 3
  • C、 Compilation fails.
  • D、 An exception is thrown at runtime.

正确答案:A

第8题:

interface A{

int x = 0;

}

class B{

int x =1;

}

class C extends B implements A {

public void pX(){

System.out.println(x);

}

public static void main(String[] args) {

new C().pX();

}

}


正确答案:

 

错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

以通过A.x 来明确。

第9题:

现有:  class Top  {     static int X=l;  public Top()  {  x*=3; }     }  class Middle extends Top  {      public  Middle()    {x+=l;  }  public static void main(String  []  args)  {     Middle m=new Middle();    System.out.println (x);    }     }  结果是什么?()    

  • A、  2
  • B、  3
  • C、  4
  • D、编译失败

正确答案:C

第10题:

public static void main( String[] args ) {  Integer a = new Integer(10);  Integer b = new Integer(10);  Integer c = a;  int d = 10;  double e = 10.0;  }   Which three evaluate to true?()   

  • A、 (a == c)
  • B、 (d == e)
  • C、 (b == d)
  • D、 (a == b)
  • E、 (b == c)
  • F、 (d == 10.0)

正确答案:A,B,F

更多相关问题