SCJP程序员认证考试

单选题23. Object [] myObjects = {  24. new integer(12),  25. new String(”foo”),  26. new integer(5),  27. new Boolean(true)  28. };  29. Arrays.sort(myObjects);  30. for( int i=0; i31. System.out.print(myObjects[i].toString());  32. System.out.print(” “);  3

题目
单选题
23. Object [] myObjects = {  24. new integer(12),  25. new String(”foo”),  26. new integer(5),  27. new Boolean(true)  28. };  29. Arrays.sort(myObjects);  30. for( int i=0; i31. System.out.print(myObjects[i].toString());  32. System.out.print(” “);  33. }  What is the result?()
A

 Compilation fails due to an error in line 23.

B

 Compilation fails due to an error in line 29.

C

 A ClassCastException occurs in line 29.

D

 A ClassCastException occurs in line 31.

E

 The value of all four objects prints in natural order.

参考答案和解析
正确答案: D
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()

A.three

B.other

C.Anexceptionisthrownatruntime.

D.Compilationfailsbecauseofanerroronline12.

E.Compilationfailsbecauseofanerroronline13.

F.Compilationfailsbecauseofanerroronline15.


参考答案:A

第2题:

以下程序的运行结果为?

class ValHold{

public int i = 10;

}

public class ObParm{

public static void main(String argv[]){

ObParm o = new ObParm();

o.amethod();

}

public void amethod(){

int i = 99;

ValHold v = new ValHold();

v.i=30;

another(v,i);

System.out.print( v.i );

}

public void another(ValHold v, int i){

i=0;

v.i = 20;

ValHold vh = new ValHold();

v = vh;

System.out.print(v.i);

System.out.print(i);

}

}

A.10030

B. 20030

C. 209930

D. 10020


正确答案:D

第3题:

本题中,用表格表现某个月的月历,其中标题是从Sunday到Saturday,表格中的各项是可以修改的。 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class java2 ( public static void main(String[]args) { try{ UIManager.setLookAndFeel(UIManager.getSys- temLookAndFeelClassName): } catch(Exception e) JFrame. frame=new CalendarTableFrame; frame.setDefaultCloseOperation(JFrame.EXIT_ oN CLOSE); frame.show; } } clasgCalendarTableFrame. extends JFrame { private static final int WIDTH=500; private static final int HEIGHT=150: private cells= { {null,null,null,new Integer(1),new Integer (2),new Integer(3),new Integer(4)), {new Integer(5),new Integer(6),new Integer (7).new Integer(8),new Integer(9),new Integer (10),new Integer(11)), {new Integer(12),new Integer(13),new Integer (14),new Integer(15),new Integer(16),new Integer (17),new Integer(18)), {new Integer(19),new Integer(20),new Integer (21),new Integer(22),new Integer(23),new Integer (24),new Integer(25)), {new Integer(26),new Integer(27),new Integer (28),new Integer(29),new Integer(30),new Integer (31),null} }; private String[]columnNames={ "Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday" }; public CalendarTableFrame{ setTitle("java2"); setSize(WIDTH,HEIGHT); JTable table=new ; getContentPane.add(new JScrollPane(table), BorderLayout.CENTER); } }


正确答案:
第1处:Object[][]
第2处:JTable(cells,columnNames)
【解析】第1处定义二维数组保存日期数据;第2处JTable的构造方法第一个参数是数据,第二个参数是表格第一行中显示的内容。

第4题:

Given:  Integer i = new Integer (42);  Long l = new Long (42);  Double d = new Double (42.0);   Which two expression evaluate to true?()

  • A、 (i = = l)
  • B、 (i = = d)
  • C、 (d = = l)
  • D、 (i.equals(d))
  • E、 (i.equals(i))
  • F、 (i.equals(42))

正确答案:D,E

第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题:

23.Object[]myObjects={24.newinteger(12),25.newString(”foo”),26.newinteger(5),27.newBoolean(true)28.};29.Arrays.sort(myObjects);30.for(inti=0;i31.System.out.print(myObjects[i].toString());32.System.out.print(”);33.}Whatistheresult?()

A.Compilationfailsduetoanerrorinline23.

B.Compilationfailsduetoanerrorinline29.

C.AClassCastExceptionoccursinline29.

D.AClassCastExceptionoccursinline31.

E.Thevalueofallfourobjectsprintsinnaturalorder.


参考答案:C

第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题:

阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内【说明】

编写字符界面的Application程序,接收依次输入的10个整型数据,每个数据一行,将这些数据按升序排序后从系统的标准输出设备输出。

【Java代码】

import java.iO.*;

import java.util.* ;

public class compositor

{

public static void main ( String args[] )

{

final int NUMBER=10;

Vector dataVector=new Vector ();

try

{

BufferedReader br=new BufferedReader (

(1) InputStreamReader ( System.in ));

System.out.println ("请输入"+NUMBER+"个整数");

for (int i=0; i<NUMBER; i++ )

{

int temp=Integer.parselnt ( br.(2));

int low=0, high=i-1, mid=0;

while ((3))

{

System.out.println ( low+","+mid+","+high );

(4);

if ((( Integer ) dataVectOr.get( mid )) .intValue () ==temp )

{

data Vector.insertElementAt ( new Integer ( temp ), mid );

break;

}

else if ((( Integer ) dataVector.get ( mid )) .intValue ( ) >temp )

{

high=mid-1;

}

else

{

(5);

}

}

if ( low>high )

{

dataVector, insertElementAt ( new Integer ( temp ), iow );

}

}

//输出

System.out.println ( "\n升序的排序结果为; ");

for (int i=0; i<NUMBER; i++ )

{

System.out.print ( dataVector.get( i ) .toString () +"\t" );

}

}

catch ( NumberFormatException nfe)

{

System.out.println ( nfe.toString ());

System.out.println ( "整数格式输入错误。");

}

catch ( IOException ioe )

{

System.out.println ( ioe.toString ());

}

}

}


正确答案:(1)new (2) readLine() (3) low=high (4) mid= (low+high )/2 (5) low=mid+1
(1)new (2) readLine() (3) low=high (4) mid= (low+high )/2 (5) low=mid+1

第9题:

public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?() 

  • A、 foofoofoofoofoo
  • B、 foobarfoobarbar
  • C、 foobarfoofoofoo
  • D、 foobarfoobarfoo
  • E、 barbarbarbarbar
  • F、 foofoofoobarbar
  • G、 foofoofoobarfoo

正确答案:D

第10题:

23. Object [] myObjects = {  24. new integer(12),  25. new String(”foo”),  26. new integer(5),  27. new Boolean(true)  28. };  29. Arrays.sort(myObjects);  30. for( int i=0; i31. System.out.print(myObjects[i].toString());  32. System.out.print(” “);  33. }  What is the result?() 

  • A、 Compilation fails due to an error in line 23.
  • B、 Compilation fails due to an error in line 29.
  • C、 A ClassCastException occurs in line 29.
  • D、 A ClassCastException occurs in line 31.
  • E、 The value of all four objects prints in natural order.

正确答案:C

更多相关问题