java语言概述习题(4)

2019-08-30 18:42

6. System.out.println(“Hello”); 7. } 8. }

A 给methodA加上方法体; B 将第5-7行的代码用“;”代替

C 将类Test前面的修饰符abstract去掉

D 将方法methodA前面的修饰符abstract去掉 E 将方法methodB前面的修饰符abstract去掉

4、下面选项中,_____可以是合法的方法重写的形式。 class BaseClass {

private float x = 0f; protected float getVar() { return x; } }

class SubClass extends BaseClass {

private float x = 0f;

____________________ }

A. float getVar() { return x; }

B. public float getVar() { return x; } C. public double getVar() { return x; } D. protected float getVar() { return x; } E. public float getVar(float f) { return f; } 5、如果有如下这样一段代码 class A { A() { } } class B extends A { }

请在下面项中,正确的说法是:____________ A、类B的构造函数的访问权限是public B、类B的构造函数没有参数

C、类B的构造函数中包含this()方法的调用 D、类B的构造函数中包含super()的调用

第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语言概述习题(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:中国小圆桌行业发展研究报告 - 图文

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: