下面程序输出的结果是什么?()public class Quiz2{ public static void main(String args[]) {try

题目

下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new MyException(); }catch(Exception e) { System.out.println("It's caught!"); }finally{ System.out.println("It's finally caught!"); } } } class MyExeeption extends Exception{}

A.It's finally caught!

B.It's caught!

C.It's caught!/It'sfinally caught!

D.无输出

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序段的输出结果为 public class MyClass { public static void main(String args[]) { String s="Helto! How are you?"; System.out.println(s.lastlndexOf("o",16)); } }

A.16

B.o

C.u

D.17


正确答案:A
解析:本题考查字符串类中常用成员函数的用法。 String类的成员函数 lastIndexOf()的原型是:public int lastIndexOf(String str,int fromIndex)。它用于获得字符串str在给定字符串中从fromIndex位置往回搜索第一次出现的地方。需要注意的是,在字符串中,下标是从。开始的。所以对于字符串s,下标为16的字母正好是o,从这里往前寻找字符串"o"第一次出现的位置,正好就是字符串中。它本身所在的位置。故s.lastIndexOf ("o",16)返回的结果就是16。

第2题:

以下Java应用程序执行入口main方法的声明中,正确的是( )。

A.public static void main()

B.public static void main(String[] args)

C.public static int main(String[] args)

D.public void main(String[] args)


参考答案:B

第3题:

下列程序的运行结果是【 】。

public class Test {

public static void main (String args[]) {

String s1="hello!";

System.out.println (s1.toUpperCase());

}}


正确答案:HELLO!
HELLO! 解析:在String类的常用方法中,toUpperCaee()方法将当前字符串中的所有小写字母转化成大写,其他字符保持不变。

第4题:

下列程序的输出结果是class Test{public static void main(String args[]){int n=7;n<<=3;n=n&am

下列程序的输出结果是 class Test{ public static void main(String args[]){ int n=7; n<<=3; n=n&n+1|n+2^n+3; n>>=2; System.out.println(n); } }

A.0

B.-1

C.14

D.64


正确答案:C
解析:本题考查Java中的运算符。首先要清楚程序里面涉及的运算符的含义。“”是按位左移运算符,“&”是按位与运算符,“|”是按位或运算符,“^”是按位异或运算符。题目中整型变量n=7相当于二进制中的111,n=3语句执行后,n值为111000,相当于十进制的56,而语句n=n&n+1|n+2^n+3执行后,n值为57;n>>=2语句执行后,n的值为14,所以选项C正确。

第5题:

下面程序的输出结果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }()

A.lava

B.java

C.编译错误

D.运行时出现异常


正确答案:B

第6题:

下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { for ( int a=0;a<10;a++) { if (a==5) break; System.out.println(A); } } }

A.01234

B.6789

C.012346789

D.5


正确答案:A
解析:题目中输出语句位于循环体内,而在if语句外,所以a5时执行输出语句。当a=5时,退出循环,结束程序的执行。

第7题:

下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

A.0

B.1

C.2

D.3


正确答案:C

第8题:

下面程序执行后的输出结果为( )。 public class fun { public static void main(String args[]) { String greets="How are you!"; String s=greets.substring(0,3); System.out.println(S); } }

A.How

B.are.

C.you

D.how ate you!


正确答案:A
解析:此题方法substring(0,3)是取字符串 greets的第1个字符开始到第3个字符组成的新字符串,即"How"。

第9题:

下列程序的输出结果是 interface Inter{ public final static int A=100; } class My implements Inter{ public static void main (String args[ ]) {System.out.println(A) ; }

A.100

B.0

C.A

D.程序有错误


正确答案:A
解析:本题主要考查接口的定义和使用,接口是一种含有抽象方法和常量的一种特殊的抽象类,不能包含成员变量,在程序中是输出常量A的值,所以输出的结果为5。

第10题:

下面程序的输出结果是______。 public class exl { public static void main(String[] args) { for(int cnt=0;cnt<10,;cnt++) { if(cnt==5) break; System.out.print(cnt); } } }

A.01234

B.012346789

C.6789

D.5


正确答案:A

更多相关问题