网页功能: 加入收藏 设为首页 网站搜索  
SCJP认证套题解析之三
发表日期:2004-07-30作者:[转贴] 出处:  

41Which of the following statements are legal?

A. long l = 4990;

B. int  i = 4L;

C. float f = 1.1;

D. double d = 34.4;

E. double t = 0.9F.

(ade)

题目:下面的哪些声明是合法的。

此题的考点是数字的表示法和基本数据类型的类型自动转换,没有小数点的数字被认为是int型数,带有小数点的数被认为是double型的数,其它的使用在数字后面加一个字母表示数据类型,加l或者Llong型,加d或者Ddouble,加f或者Ffloat,可以将低精度的数字赋值给高精度的变量,反之则需要进行强制类型转换,例如将int,short,byte赋值给long型时不需要显式的类型转换,反之,将long型数赋值给byte,short,int型时需要强制转换(int a=(int)123L;)。

 

42

public class Parent {

     int change() {…}

   }

   class Child extends Parent {

  

   }

Which methods can be added into class Child?

A. public int change(){}

B. int chang(int i){}

C. private int change(){}

D. abstract int chang(){}

(ab)

题目:哪些方法可被加入类Child

这个题目的问题在第35题中有详尽的叙述。需要注意的是答案D的内容,子类可以重写父类的方法并将之声明为抽象方法,但是这引发的问题是类必须声明为抽象类,否则编译不能通过,而且抽象方法不能有方法体,也就是方法声明后面不能带上那两个大括号({}),这些D都不能满足。

 

43

class Parent {

     String one, two;

     public Parent(String a, String b){

        one = a;

        two = b;

     }

     public void print(){ System.out.println(one); }

   }

   public class Child extends Parent {

      public Child(String a, String b){

        super(a,b);

      }

      public void print(){

           System.out.println(one + " to " + two);

      }

      public static void main(String arg[]){

           Parent p = new Parent("south", "north");          

           Parent t = new Child("east", "west");

           p.print();

           t.print();

      }

   }

Which of the following is correct?

A. Cause error during compilation.

B. south

   east

C. south to north

   east to west

D. south to north

   east

E. south

   east to west

(e)

题目:下面的哪些正确。

A.      在编译时出错。

这个题目涉及继承时的多态性问题,在前面的问题中已经有讲述,要注意的是语句t.print();在运行时t实际指向的是一个Child对象,即java在运行时决定变量的实际类型,而在编译时t是一个Parent对象,因此,如果子类Child中有父类中没有的方法,例如printAll(),那么不能使用t.printAll()。参见12题的叙述。

 

44A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should be used?

A. FlowLayout

B. CardLayout

C. North and South of BorderLayout

D. East and West of BorderLayout

E. GridLayout

(d)

题目:一个按钮放在一个框架中,在框架改变时只影响按钮的高度而宽度不受影响,应该使用哪个布局管理器?

这个还是布局管理器的问题,流布局管理器(FlowLayout)将根据框架的大小随时调整它里面的组件的大小,包括高度和宽度,这个管理器不会约束组件的大小,而是允许他们获得自己的最佳大小,一行满了以后将在下一行放置组件;卡片管理器(CardLayout)一次显式一个加入的组件(根据加入时的关键字);网格管理器(GridLayout)将容器划分为固定的网格,容器大小的改变将影响所有组件的大小,每个组件的大小都会同等地变化;边界管理器(BorderLayout)将容器划分为五个区域,分为东南西北和中间,东西区域的宽度为该区域里面组件的最佳宽度,高度为容器的高度减去南北区域的高度,这是一个可能变化的值,而南北区域的宽度为容器的整个宽度,高度为组件的最佳高度,中间区域的高度为容器的高度减去南北区域的高度,宽度为容器的宽度减去东西区域的宽度。

 

45Given the following code:

    1)   class Parent {

    2)     private String name;

    3)     public Parent(){}

    4)   }

    5)   public class Child extends Parent {

    6)     private String department;

    7)     public Child() {}

    8)     public String getValue(){ return name; }

    9)     public static void main(String arg[]) {

    10)       Parent p = new Parent();

    11)    }

    12)  }

Which line will cause error?

A. line 3

B. line 6

C. line 7

D. line 8

E. line 10

(d)

题目:给出下面的代码:

哪些行将导致错误。

8行的getValue()试图访问父类的私有变量,错误,参看前面有关变量类型及其作用域的叙述。

 

46The variable "result" is boolean. Which expressions are legal?

A. result = true;

B. if ( result ) { // do something... }

C. if ( result!= 0 ) { // so something... }

D. result = 1

(ab)

题目:变量"result"是一个boolean型的值,下面的哪些表达式是合法的。

Javaboolean不同于c或者c++中的布尔值,在javaboolean值就是boolean值,不能将其它类型的值当作boolean处理。

 

47Class Teacher and Student are subclass of class Person.

    Person p;

    Teacher t;

    Student s;

    p, t and s are all non-null.

    if(t instanceof Person) {  s = (Student)t; }

What is the result of this sentence?

A. It will construct a Student object.

B. The expression is legal.

C. It is illegal at compilation.

D. It is legal at compilation but possible illegal at runtime.

(c)

题目:类TeacherStudent都是类Person的子类

p,ts都是非空值

这个语句导致的结果是什么

A.      将构造一个Student对象。

B.      表达式合法。

C.      编译时非法。

D.     编译时合法而在运行时可能非法。

instanceof操作符的作用是判断一个变量是否是右操作数指出的类的一个对象,由于java语言的多态性使得可以用一个子类的实例赋值给一个父类的变量,而在一些情况下需要判断变量到底是一个什么类型的对象,这时就可以使用instanceof了。当左操作数是右操作数指出的类的实例或者是子类的实例时都返回真,如果是将一个子类的实例赋值给一个父类的变量,用instanceof判断该变量是否是子类的一个实例时也将返回真。此题中的if语句的判断没有问题,而且将返回真,但是后面的类型转换是非法的,因为t是一个Teacher对象,它不能被强制转换为一个Student对象,即使这两个类有共同的父类。如果是将t转换为一个Person对象则可以,而且不需要强制转换。这个错误在编译时就可以发现,因此编译不能通过。

 

48Given the following class:

    public class Sample{

       long length;

       public Sample(long l){ length = l; }

       public static void main(String arg[]){

          Sample s1, s2, s3;

          s1 = new Sample(21L);

          s2 = new Sample(21L);   

          s3 = s2;

          long m = 21L;

       }

    }

Which expression returns true?

A. s1 == s2;

B. s2 == s3;

C. m == s1;

D. s1.equals(m).

(b)

题目:给出下面的类:

哪个表达式返回true

前面已经叙述过==操作符和Stringequals()方法的特点,另外==操作符两边的操作数必须是同一类型的(可以是父子类之间)才能编译通过。

 

49Given the following expression about List.

      List l = new List(6,true);

Which statements are ture?

A. The visible rows of the list is 6 unless otherwise constrained.

B. The maximum number of characters in a line  will be 6.

C. The list allows users to make multiple selections

D. The list can be selected only one item.

(ac)

题目:给出下面有关List的表达式:

哪些叙述是对的。

A.      在没有其它的约束的条件下该列表将有6行可见。

B.      一行的最大字符数是6

C.      列表将允许用户多选。

D.     列表只能有一项被选中。

List组件的该构造方法的第一个参数的意思是它的初始显式行数,如果该值为0则显示4行,第二个参数是指定该组件是否可以多选,如果值为true则是可以多选,如果不指定则缺省是不能多选。

 

50Given the following code:

    class Person {

       String name,department;

       public void printValue(){

          System.out.println("name is "+name);

          System.out.println("department is "+department);

       }

    }

    public class Teacher extends Person {

       int salary;

       public void printValue(){

          // doing the same as in the parent method printValue()

          // including print the value of name and department.

          System.out.println("salary is "+salary);

       }

    }

Which expression can be added at the "doing the same as..." part of the method printValue()?

A. printValue();

B. this.printValue();

C. person.printValue();

D. super.printValue().

(d)

题目:给出下面的代码:

下面的哪些表达式可以加入printValue()方法的"doing the same as..."部分。

子类可以重写父类的方法,在子类的对应方法或其它方法中要调用被重写的方法需要在该方法前面加上”super.”进行调用,如果调用的是没有被重写的方法,则不需要加上super.进行调用,而直接写方法就可以。这里要指出的是java支持方法的递归调用,因此答案ab在语法上是没有错误的,但是不符合题目代码中说明处的要求:即做和父类的方法中相同的事情?D?D打印名字和部门,严格来说也可以选ab

 

51Which is not a method of the class InputStream?

A. int read(byte[])

B. void flush()

C. void close()

D. int available()

(b)

题目:下面哪个不是InputStream类中的方法

这个题目没有什么好说的,要求熟悉java API中的一些基本类,题目中的InputStream是所有输入流的父类,所有要很熟悉,参看JDKAPI文档。方法void flush()是缓冲输出流的基本方法,作用是强制将流缓冲区中的当前内容强制输出。

 

52Which class is not subclass of FilterInputStream?

A. DataInputStream

B. BufferedInputStream

C. PushbackInputStream

D. FileInputStream

(d)

题目:

哪个不是FilterInputStream的子类。

此题也是要求熟悉API基础类。Java基础API中的FilterInputStream 的已知子类有:BufferedInputStream, CheckedInputStream, CipherInputStream, DataInputStream, DigestInputStream, InflaterInputStream, LineNumberInputStream, ProgressMonitorInputStream, PushbackInputStream

 

53Which classes can be used as the argument of the constructor of the class FileInputStream?

A. InputStream

B. File

C. FileOutputStream

D. String

(bd)

题目:哪些类可以作为FileInputStream类的构造方法的参数。

此题同样是要求熟悉基础APIFileInputStream类的构造方法有三个,可接受的参数分别是:FileFileDescriptorString类的一个对象。

 

54Which classes can be used as the argument of the constructor of the class FilterInputStream?

A. FilterOutputStream

B. File

C. InputStream

D. RandomAccessFile

(c)

题目:哪些类可以作为FilterInputStream类的构造方法的参数。

FilterInputStream的构造方法只有一个,其参数是一个InputStream对象。

 

55Given the following code fragment:

1) switch(m)

2) { case 0: System.out.println("case 0");

3)   case 1: System.out.println("case 1"); break;

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 SCJP认证套题解析之三
本类热点文章
  Java读取文件中含有中文的解决办法
  Java读取文件中含有中文的解决办法
  简单加密/解密方法包装, 含encode(),de..
  EJB 3.0规范全新体验
  java简单的获取windows系统网卡mac地址
  让Java程序带着JRE一起上路
  抢先体验"野马"J2SE6.0
  Java连接各种数据库的实例
  Java连接各种数据库的实例
  JAVA的XML编程实例解析
  Java学习从入门到精通(附FAQ)
  新手必读:Java学习的捷径
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.01179