Java认证考试

现有:  class  Wrench2  {      int size;  public static void main(String  []  args)  {      Wrench2 w=new Wrench2();      w.size=II;  Wrench2 w2=go(w, w.size);     System. out .print (w2. size);      }  static Wrench2 go(Wrench2 wr. int s)  {      S=12;  re

题目

现有:  class  Wrench2  {      int size;  public static void main(String  []  args)  {      Wrench2 w=new Wrench2();      w.size=II;  Wrench2 w2=go(w, w.size);     System. out .print (w2. size);      }  static Wrench2 go(Wrench2 wr. int s)  {      S=12;  return wr;     }     } 结果为()    

  • A、 11
  • B、 12
  • C、编译失败
  • D、运行时异常被抛出
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

现有:classWrench2{intsize;publicstaticvoidmain(String[]args){Wrench2w=newWrench2();w.size=II;Wrench2w2=go(w,w.size);System.out.print(w2.size);}staticWrench2go(Wrench2wr.ints){S=12;returnwr;}}结果为()

A.11

B.12

C.编译失败

D.运行时异常被抛出


参考答案:A

第2题:

下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }

A.x=10

B.x=20

C.x=6

D.编译不通过


正确答案:C
C。【解析】本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的90方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量Y的值。从main方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给X和Y赋值,X=a.Y后,X值为6,再返回去执行System.out.println("x="+b.x)语句,输出为x=6,可见,正确答案为选项C。

第3题:

下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i,String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String[]args){ print(99,"Int first"); } }

A.String:String first,int:11

B.int:11,String:Int first

C.String:String first,int99

D.int:99,String:Int first


正确答案:D
解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,"Int first"),根据构造方法的参数类型选择调用方法,这里调用的是print(int i,String s)方法,因此输出的是int:99,String:Int first。

第4题:

class Wrench {  public static void main(String [] args) {  Wrench w = new Wrench(); Wrench w2 = new Wrench();  w2 = go(w,w2);  System.out.print(w2 == w);  }  static Wrench go(Wrench wr1, Wrench wr2) {  Wrench wr3 = wr1; wr1 = wr2; wr2 = wr3;  return wr3; }  }  结果是什么?() 

  • A、true
  • B、false
  • C、编译失败
  • D、输出不可预期

正确答案:A

第5题:

3下列程序段运行的结果为( )。 public class Test{ static void print(String s,int i){ System.out.pdntlnC String: "+s+",int:"+i); } static void print(iht i,String s){ System.out.prinflnCint:"+i+",gtring:"+s); } public static void main(String[] args){ print(99,"Int first"); } }

A.String:String first,int: 11

B.int: 11,String:Int first

C.String:String first,int:99

D. int:99,Stfing:Int first


正确答案:D

第6题:

下列程序段运行的结果为 public class Test{ static void print(String s,int i){ System.out.println("String:"+s+",int:"+i); } static void print(int i, String s){ System.out.println("int:"+i+",String:"+s); } public static void main(String [] args){ print(99,"Int first"); } }

A.String:Stringfirst,int:11

B.int:11,String:Int first

C.String:String first,int:99

D.int:99,String:int first


正确答案:D
解析:本题考查考生阅读程序的能力。JavaApplication都是以main()方法作为入口,首先执行的是print(99,“Intfirst”),根据构造方法的参数类型选择调用方法,这里调用的是print(inti,Strings)方法,因此输出的是int:99,String:Intfirst。

第7题:

下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

A.x=10

B.x=20

C.x=6

D.编译不通过


正确答案:C
解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println(”x=”+b.x)语句,输出为x=6,可见,正确答案为选项C。

第8题:

classWrench2{intsize;publicstaticvoidmain(String[]args){Wrench2w=newWrench2();w.size=9;Wrench2w2=go(w,w.size);System.out.print(w2.size);}staticWrench2go(Wrench2wr,ints){s=7;returnwr;}}结果为:()

A.7

B.9

C.编译失败

D.输出结果不可预料


参考答案:B

第9题:

现有:  class Passer f  static final int X=5;  public  static void main (String  []  args)  {      new  Passer().go (x);      System. out .print (x);      }  void go (int x)  {     System. out .print(x++);     }     结果是什么?()     

  • A、55
  • B、56
  • C、65
  • D、66

正确答案:A

第10题:

现有:  class Tree {  private static String tree = "tree ";  String getTree ()  {  return tree;  }       }  class Elm extends Tree {  private static String tree = "elm ";  public static void main (String  []  args)  {       new Elm() .go (new Tree())  ;      } }  void go (Tree t)  {  String  s =  t.getTree () +Elm.tree  +  tree  +   (new  Elm() .getTree ()) ;      System.out.println (s) ;}     结果为:()                 

  • A、 elm elm elm elm
  • B、 tree elm elm elm
  • C、 tree elm elm tree
  • D、 tree elm tree elm

正确答案:C

更多相关问题