19、Java.lang.RuntimeException及其子类的异常可以不捕获。( 对 )
20、当用户在TextField中改变光标的位置时,会产生一个TextEvent事件。( 错 ) 31、Java程序是由若干类定义组成的,类定义包括定义类头和定义类体。( 对 ) 32、类Class1中的属性被private修饰符修饰为私有变量,所以方法不能访问它。( 错 ) 34、引用一个类的属性或调用其方法,必须以这个类的对象为前缀。( 错 ) 35、与未加访问控制符的缺省情况相比,public和protected修饰符扩大了类及其属性和方法的被访问范围,private修饰符则缩小了这种范围。( 对 ) 36、子类要调用父类的方法,必须使用super关键字。( 错 ) 37、因为Java不支持多重继承,所以定义类时implements关键字后面只能说明一个接口名。( 错 )
38、挂起、阻塞或等待的线程都能恢复执行,但停止的线程不能复生。( 对 ) 39、如果一个方法在运行过程中产生异常,则方法会终止,但整个应用不一定终止。( 对 ) 40、接口Java.lang.runnable中只有一个run()方法。( 对 )
三、程序阅读题
1.阅读下面的程序代码,并回答问题。
String s1 = new String(\String s2 = new String(\ boolean b1= s1.equals(s2);
boolean b2 = s1 = = s2; System.out.print(b1+\ \
(1)程序段执行后,在命令行的输出结果如何? (2)解释输出(1)的结果的原因? (1) true false
(2 )equals方法比较两个字符串的内容是否相等;运算符“==”判断两个对象是否指向同一个引用,即是否为同一个对象。
2.阅读下面的程序代码,并回答问题。
import java.io.*; public class Test {
public static void main(String args[]) throws IOException { BufferedReader buf=new BufferedReader(
new InputStreamReader(System.in)); while(true) {
String str = buf.readLine(); if(str.equals(\ break;
int x=Integer.parseInt(str);
System.out.println(x*x); } } }
编译运行上面的程序:
(1)从键盘输入10,回车后输出的结果如何?
(2)从键盘输入exit,回车后程序能正确执行吗?为什么? (1)100
(2)不能;因为方法Integer.parseInt(str)不能将字符串“exit”转化为整数,抛出异常。
3. 阅读下面的程序代码
import java.io.* ; public class Test{
public static void main(String args[ ]){ int i , s=0;
     int a[ ]={ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ,90};      for( i=0 ; i      System.out.println(\    }    }  程序执行后,在命令行的输出结果是什么?  270   4. 阅读下面的程序代码 import java.util.*;  public class Example9_14 {     public static void main(String args[]) {        String s=\市话费:28.89元,长途话费:128.87元,上网费:298元。\      String delim = \市话长途话上网费元:,。\       StringTokenizer fenxi=new StringTokenizer(s,delim);//用delim中的字符的任意组合作为分隔标记         double totalMoney=0;        while(fenxi.hasMoreTokens()) {            double money=Double.parseDouble(fenxi.nextToken());           System.out.println(money);           totalMoney += money;       }        System.out.println(\总费用:\元\    }  }  程序执行后,在命令行的输出结果是什么? 市话费:28.89元 长途话费:128.87元, 上网费:298元。 总费用:455.76元       5. 阅读下面的程序代码 import java.util.*;  class Student implements Comparable {    int english=0;    String name;     Student(int english,String name) {       this.name=name;       this.english=english;    }     public int compareTo(Object b) {       Student st=(Student)b;        return (this.english - st.english);    } }  public class Example13_8 {    public static void main(String args[]) {       TreeSet      st1=new Student(90,\赵一\     st2=new Student(66,\钱二\     st3=new Student(86,\孙三\     st4=new Student(76,\李四\     mytree.add(st1);      mytree.add(st2);      mytree.add(st3);      mytree.add(st4);       Iterator         System.out.println(\     }   } }  程序执行后,在命令行的输出结果是什么? 钱二 66 李四76 孙三86 赵一90    6. 写出下面的程序编译、运行后的结果。 public class Test{       public static void main(String args[]) {          new Student(\         new Student(\         new Student(\          System.out.println(\         Student.print();      }  }     class Student {       protected  String   name;      protected  char     sex;      protected  int      chinese;      protected  int      english; 
相关推荐: