单选题研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。A10  数组越界  程序结束B10   程序结束C数组越界  程序结束D程序结束

单选题
研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i<6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。
A

10  数组越界  程序结束

B

10   程序结束

C

数组越界  程序结束

D

程序结束


参考解析

解析: 暂无解析

相关考题:

试题八(共15分)阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类HeadDecorator 与FootDecorator 分别完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!------------------------这是票据的台头!这是票据的脚注![Java程序代码]public class SalesTicket {public void printTicket() {System.out.println("这是票据正文!");}}public class Decorator extends SalesTicket{SalesTicket ticket;}}public class FootDecorator extends Decorator{public FootDecorator(SalesTicket t) {(2) ;}public void printTicket() {super.printTicket();System.out.println("这是票据的脚注!");}}public class Main {public static void main(String[] args) {T = new HeadDecorator( (3) );T. (4) ;System.out.println("------------------------");T = new FootDecorator( (5) );T.printTicket();}}public Decorator(SalesTicket t){ticket = t;}public void printTicket(){if(ticket != null)ticket.printTicket();}}public class HeadDecorator extends Decorator{public HeadDecorator(SalesTicket t) {(1) ;}public void printTicket() {System.out.println("这是票据的台头!");super.printTicket();

阅读下列代码段,选出该代码段的正确文件名( )。 class A { void methodl() { 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.javaB.A.classC.B.classD.B.java

阅读下列代码段,选出该代码段的正确文件名( )。 class A { void method1() { System.out.println("method1 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.javaB.A.classC.B.classD.B.java

在下面Java Applet程序的下画线处填入代码,使程序完整并能够正确运行。import java.applet.*;import java.awt.*;public class HelloWorld ______ {public void paint(Graphics g) {g.drawString("Hello World!",25,25);}}

在如下源代码文件Test.java中, 哪个是正确的类定义?() A.public class test { public int x = 0; public test(int x) { this.x = x; } }B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }D.public class

如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。AB.java文件代码如下;package test;public class AB{int a=60;public void show(){System.out.println(”a=”+a);}Example.java文件代码如下:import test.AB;class Example{public static void main(String args[]){AB bj=new AB();obj.show();}}

在下列代码的下i画线处应填人的内容是( )。 public class FirstSample{ public static void main( args[]){ System.out.println("你好!"); } }A.staffB.doubleC.intD.String

下列哪个选项的java源文件代码片段是不正确的?A.package testpackage; public class Test{ }B.import java. io. *; package testpaekage; public class Test { }C.import java.io.*; class Person { } public class Test { }D.import java.io.*; import java. awt.*; public class Test{ }

在下列源代码文件Test.java中,正确定义类的代码是( )。A.pblic class test { public int x=0; public test(int x) { this. x=x;} }B.public class Test { public int x=0; public Test(int x) { this. x=x;} }C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }

下列哪个选项的java源文件程序段是不正确的? ( )A.package testpackage; public class Test{ }B.import java.io.*; package testpackage; public class Test{ }C.import java.i.*; class Person{} public class Test{ }D.import java.io.*; import java.awt.*; public class Test { }

阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的Java程序代码中,类SalesTicket能够完成打印票据正文的功能,类 HeadDecorator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!-------------------这是票据的脚注!这是票据的台头!这是票据的脚注!【tava程序代码】public class SalesTicket {public void printTicket() {System. out. println ( "这是票据正文 ! ");}}public class Decorator extends SalesTicket{SalesTicket ticket;public Decorator(SalesTicket t) {ticket = t;}public void printTicket(){if(ticket != null)ticket.printTicket();}public class HeadDecorator extends Decorator{public HeadDecorator(SalesTicket t) {(1)}public void printTicket() {System. out.println("这是票据的台头! ");super.printTicket();}}public class FootDecorator extends Decorator{public FootDecorator(SalesTicket t) {(2);}public void printTicket() {super, printTicket ();System. out.println ("这是票据的脚注!");}}public class Main {public static void main(String[] args) {T = new HeadDecorator( (3));T=(4);System.out.println("------------------------------------");T = new FootDecorator((5));T.printTicket ();}}

阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。[说明]某应急交通控制系统(TraficControlSystem)在红灯时控制各类车辆(Vehicle)的通行,其类图如下图所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。下面的Java代码实现以上设计,请完善其中的空缺。[Java代码]abstract class Vehicle{public Vehicle(){ }abstract void run();};interface Emergency{ ______; ______;};class Car extends Vehicle{public Car(){ }void run(){ /*代码略*/ }};Class Truck extends Vehicle{public Truck(){ }void run() { /*代码略*/ }};class PoliceCar ______ {boolean isEmergency= false;public PoliceCar(){ }public PoliceCar(boolean b) {this.isEmergency=b; }public boolean isEmergent(){ return ______ }public void runRedLight(){ /*代码略*/ }};/*类Ambulance、FireEngine实现代码略*/public class TraficControlsystem { /*交通控制类*/private Vehicle[]V=new Vehicle[24];int numVehicles;public void control(){for {int i=0; i<numVehicles; i++){if(V[i]instanceof Emergency}else______. run();}}void add(Vehicle vehicle){ v[numVehicles++]=vehicle;}/*添加车辆*/void shutDown(){/*代码略*/}public static void main(String[]args){TraficC0ntrolSystem tcs=new TraficControlSystem();tcs.add(new Car());tcs.add(new PoliceCar());tcs.add(new Ambulance());tcs.add(new Ambulance(true));tcs.add(new FireEngine(true));tcs.add(new Truck());tcs.add(new FireEngine());tcs.control();tcs.shutDown();}}

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 5-1 所示。【Java代码】import java.util.*; interface BrakeBehavior{public (1) ;/*其余代码省略*/}class LongWheelBrake implements BrakeBehavior{public void stop(){System.out.println("模拟长轮胎刹车痕迹! ");}/*其余代码省略*/}class ShortWheelBrake implements BrakeBehavior {public void stop(){System.out.println("模拟短轮胎刹车痕迹! ");}/*其余代码省略 */}abstract class Car{protected (2) wheel;public void brake(){ (3) ;}/*其余代码省略*/}class ShortWheelCar extends Car {public ShortWheelCar(BrakeBehavior behavior){(4) ; } /*其余代码省略*/}class StrategyTest{public static void main(String[]args){BrakeBehaviorbrake =new ShortWheelBrake();ShortWheelCar car1= new ShortWheelCar(brake);car1. (5) ;}}

研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。       A、10  数组越界  程序结束B、10   程序结束C、数组越界  程序结束D、程序结束

public class EqTest{()  Public static void main(String args[])  EqTest e=new EqTest(); }  EqTest(){  String s=”Java”; String s2=”java”;  //在这儿放置测试代码  {Systrm.out.println(“相等”);  Else{System.out.println(“不相等”)} }  } 在上面的java代码的注释行位置,放置()测试代码能输出“相等”结果 A、if(s==s2)B、if(s.equals(s2))C、if(s.equalsIgnoreCase(s2))D、if(s.noCaseMatch(s2))

Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()A、 Class a will not compile.B、 Line 46 can throw the unchecked exception TestException.C、 Line 45 can throw the unchecked exception TestException.D、 Line 46 will compile if the enclosing method throws a TestException.E、 Line 46 will compile if enclosed in a try block, where TestException is caught.

Public class test (  Public static void stringReplace (String text)  (  Text = text.replace (‘j’ , ‘i’);  )  public static void bufferReplace (StringBuffer text)  (  text = text.append (“C”)  )   public static void main (String args[]}  (  String textString = new String (“java”);  StringBuffer text BufferString = new StringBuffer (“java”);  stringReplace (textString);  BufferReplace (textBuffer);  System.out.printLn (textString + textBuffer);  )  )   What is the output?()

1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()  A、 No code is necessary.B、 throws ExceptionC、 catch ( Exception e )D、 throws RuntimeExceptionE、 catch ( TestException e)

public class ExceptionTest {   class TestException extends Exception {}   public void runTest () throws TestException {}   public void test () /* Point X*/ {   runTest ();   }   }   At point X on line 4, which code can be added to make the code compile?()  A、 Throws Exception.B、 Catch (Exception e).C、 Throws RuntimeException.D、 Catch (TestException e).E、 No code is necessary.

public class Foo {  static int[] a;  static { a[0]=2; }  public static void main( String[] args) {}  }  Which exception or error will be thrown when a programmer attempts to run this code?() A、 java.lang. StackOverflowErrorB、 java.lang.IllegalStateExceptionC、 java.lang.ExceptionlnlnitializerErrorD、 java.lang.ArraylndexOutOfBoundsException

Java语言中常量的定义是哪项?()A、 public staticB、 public static finalC、 finalD、 public static abstract

以下的Java程序代码中,错误的行是()  A、  public class FirstAdd{        }B、  public static void main(String args[]){        }C、  注释:显示 “天天好心情!”D、  System.out.println(“天好心情!”);

单选题public class MyExample{    public static void main(String args[])    {         System.out.println(args[2])   }} 如果以下列命令行运行:  java MyExample Aptech online 上述代码将输出()。AMyExampleBAptechCOnlineD产生异常: java.lang.ArrayIndexOutOfBoundsException

单选题public class ExceptionTest {  class TestException extends Exception {}  public void runTest () throws TestException {}  public void test () /* Point X*/  {  runTest ();  }  }   At point X on line 4, which code can be added to make the code compile?()A Throws Exception.B Catch (Exception e).C Throws RuntimeException.D Catch (TestException e).E No code is necessary.

单选题研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。A10  数组越界  程序结束B10   程序结束C数组越界  程序结束D程序结束

填空题Public class test (    Public static void stringReplace (String text) (    Text = text.replace („j„ , „i„);    )      public static void bufferReplace (StringBuffer text) (    text = text.append (“C”)   )      public static void main (String args ){  String textString = new String (“java”);    StringBuffer text BufferString = new StringBuffer (“java”);      stringReplace (textString);    BufferReplace (textBuffer);      System.out.printIn (textString + textBuffer);    }   )   What is the output?()

单选题1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()A No code is necessary.B throws ExceptionC catch ( Exception e )D throws RuntimeExceptionE catch ( TestException e)

单选题public class Foo {  static int[] a;  static { a[0]=2; }  public static void main( String[] args) {}  }  Which exception or error will be thrown when a programmer attempts to run this code?()A java.lang. StackOverflowErrorB java.lang.IllegalStateExceptionC java.lang.ExceptionlnlnitializerErrorD java.lang.ArraylndexOutOfBoundsException