文档详情

java复习题及答案.doc

发布:2017-05-18约1.75万字共16页下载文档
文本预览下载声明
一、选择 1.下面哪些是java语言中的关键字? A.sizeof B.abstract C.NULL D.Native 2.下面语句哪个是正确的? A.char=abc; B.long l=oxfff; C.float f=0.23; D.double=0.7E-3; 3.以下程序测试String 类的各种构造方法,试选出其运行效果。   class STR{    public static void main(String args[]){     String s1=new String();     String s2=new String(String 2);     char chars[]={a, ,s,t,r,i,n,g};     String s3=new String(chars);     String s4=new String(chars,2,6);     byte bytes[]={0,1,2,3,4,5,6,7,8,9};     StringBuffer sb=new StringBuffer(s3);     String s5=new String(sb);     System.out.println(The String No.1 is +s1);     System.out.println(The String No.2 is +s2);     System.out.println(The String No.3 is +s3);     System.out.println(The String No.4 is +s4);     System.out.println(The String No.5 is +s5);    } }A.The String No.1 is  The String No.2 is String 2 The String No.3 is a string The String No.4 is string The String No.5 is a string B.The String No.1 is The String No.2 is String 2 The String No.3 is a string The String No.4 is tring The String No.5 is a string C.The String No.1 is The String No.2 is String 2 The String No.3 is a string The String No.4 is strin The String No.5 is a string D.以上都不对4.下面语句段的输出结果是什么?   int i = 9;   switch (i) {   default:   System.out.println(default);   case 0:   System.out.println(zero);   break;   case 1:   System.out.println(one);   case 2: System.out.println(two); } A.default B.default, zero C.error default clause not defined D.no output displayed 5.有关类Demo,哪句描述是正确的?   public class Demo extends Base{   private int count;   public Demo(){    System.out.println(A Demo object has been created);   }   protected void addOne() {count++; } } A.当创建一个Demo类的实例对象时,count的值为0。B.当创建一个Demo类的实例对象时,count的值是不确定的。C.超类对象中可以包含改变count 值的方法。D.Demo的子类对象可以访问count。当编译和运行下列程序段时,会发生什么?   class Base {}   class Sub extends Base {}   class Sub2 extends Base {}   public class CEx{    public static void main(String argv[]){    Base b = new Base();    Sub s = (Sub) b;
显示全部
相似文档