第一范文网 - 专业文章范例文档资料分享平台

java语言概述习题

来源:用户分享 时间:2025/11/3 12:28:44 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

第6章内部类与异常类练习题答案

一、填空题

1、Throwable类有两个子类,分别是______和_______.Error和 Exception

2、所有异常的根类是_____,throw关键字的作用是____。Throwable类引发异常

3、try关键字负责_______,再来由catch关键字来_________。定义处理异常的程序捕获异常

4、补足代码;

要求调用两个函数,要求用匿名内部类 interface Inter {

void show(int a,int b); void func(); }

class Demo {

public static void main(String[] args) { //

Inter in = new Inter() {

public void show(int a,int b) { }

public void func() { } };

in.show(4,5); in.func(); } }

5、下面程序的输出结果是:_______。B C D 写出程序结果 class Demo {

public static void func() { try {

throw new Exception(); }

finally {

System.out.println(\ } }

public static void main(String[] args) { try { func();

System.out.println(\ }

catch(Exception e) {

System.out.println(\ }

System.out.println(\ } } 6、在

java中所有的异常类都继承自______类,它有两个直接子类,一个是Error类,另一个是_____类。java.lang.Throwable Exception

7、Java语言中,可以用throw语句和throws语句抛出异常,其中____语句的作用是用来改变程序的执行流程,使程序跳到相应的异常处理语句中执行。____语句把异常向上移交给调用这个方法的方法来处理。throw throws 8、下述代码执行后的结果是________?ACD public class X {

public static void main(String [] args) { try {

badMethod();

System.out.print(“A”); }

catch (Exception ex){ System.out.print(“B”); } finally { System.out.print(“C”); } System.out.print(“D”); }

public static void badMethod() {} }

单选题:

1、下面选项中,_______不能用在throw语句中?C

A. Error B. RuntimeException C. Object D. Throwable E. Exception

第9章String类练习题答案

一、填空

1、程序执行后的显示结果是_____。abcdefabcDEF public class Question {

public static void main (String args[]) { String s1 = “abc”;

String s2 = “def”;

String s3 = s1.concat(s2.toUpperCase()); System.out.println(s1+s2+s3); }

}

2、String s1 = “ab”; String s2 = “abcd”; System.out.print(“s1 “ + (( s1== s2) ? “!=”) + “ s2”); 这个代码段显示的结果是_____?s1 != s2

3、下面程序段输出结果的第一行是_____,第二行是_____。rtrme r String s=\ String s2=s.substring(7); String s3=s2.replace('m','u'); System.out.println(s2);

System.out.println(s3.charAt(2));

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

4、第5行的时候foo的值是_____? baseball String foo = “base”; foo.substring(0,3);

foo.concat(“ket”); foo += “ball”;

5、如下这段代码执行后,字符串s的值是________? hello there String s=”hello”; s.concat(“mrs”); s.toUpperCase(); s+=” there”;

6、下面这段程序执行后,屏幕上显示的是:________。True public class Exam{

public static viod main(String[] args){ char char1[]={‘t’,’e’,’s’,’t’};

char char2[]={‘t’,’e’,’s’,’t’,’1’}; String s1=new String(char1); String s2=new String(char2,0,4); System.out.println(s.equals(s2)); } }

7、请问执行完这段代码后,显示结果是_______?abcd String a = “ABCD”;

String b = a.toLowerCase(); b.replace(‘a’, ‘d’); b.replace(‘b’, ‘c’);

==” : “ System.out.println(b);

8、Java中,用来获取字符串长度的函数是_____,用来取字符串子串的函数是___。length() substring()

9、以下代码段将创建________个对象。1 String s1=”bc”;

String s2=”bc”;

10、有下面这样的代码段,总共产生了________个对象。2 String A, B, C ;

A = new String( \ B = A ; C = A + B ; 二、多选题

11、有如下一段代码: Integer s = new Integer(9); Integer t = new Integer(9); Long u = new Long(9);

则下面选项中返回值为true的是:________。C E A. (s==u) B. (s==t)

C. (s.equals(t)) D. (s.equals(9))

E. (s.equals(new Integer(9))

搜索更多关于: java语言概述习题 的文档
java语言概述习题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8c20j5wt3h1oiru32mbf_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top