JAVA认证历年真题:SCJP考试真题和解析[2]


作者:王志南 | 来源:ExamLink.com收集整理 | 日期:04-02 | 字体: [ ]

本文简介:FilterInputStream的构造方法只有一个,其参数是一个InputStream对象。

48、Given 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。

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

  49、Given 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则是可以多选,如果不指定则缺省是不能多选。

  50、Given 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支持方法的递归调用,因此答案a和b在语法上是没有错误的,但是不符合题目代码中说明处的要求:即做和父类的方法中相同的事情??打印名字和部门,严格来说也可以选a和b

51、Which 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是所有输入流的父类,所有要很熟悉,参看JDK的API文档。方法void flush()是缓冲输出流的基本方法,作用是强制将流缓冲区中的当前内容强制输出。

  52、Which 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 。

  53、Which classes can be used as the argument of the constructor of the class
FileInputStream?
  A. InputStream

  B. File

  C. FileOutputStream

  D. String

  (bd)

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

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

  54、Which 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对象。

  55、Given the following code fragment:
  1) switch(m)

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

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

  4) case 2:

  5) default: System.out.println("default");

  6) }
  Which value of m would cause "default" to be the output?

  A. 0

  B. 1

  C. 2

  D. 3

  (cd)

  题目:给出下面的代码片断:
  …
  m为哪些值将导致"default"输出。

  此题考察switch语句的用法,switch的判断的条件必须是一个int型值,也可以是byte、short、char型的值,case中需要注意的是一个case后面一般要接一个break语句才能结束判断,否则将继续执行其它case而不进行任何判断,如果没有任何值符合case列出的判断,则执行default的语句,default是可选的,可以没有,如果没有default而又没有任何值匹配case中列出的值则switch不执行任何语句

56、Given the uncompleted method:
  1)

  2) { success = connect();

  3) if (success==-1) {
  
  4) throw new TimedOutException();

  5) }

  6)}
  TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1?

  A. public void method()

  B. public void method() throws Exception

  C. public void method() throws TimedOutException

  D. public void method() throw TimedOutException

  E. public throw TimedOutException void method()

  (bc)

  题目:给出下面的不完整的方法:
  …
  TimedOutException 不是一个RuntimeException。下面的哪些声明可以被加入第一行完成此方法的声明。


  如果程序在运行的过程中抛出异常,而这个异常又不是RuntimeException或者Error,那么程序必须捕获这个异常进行处理或者声明抛弃(throws)该异常,捕获异常可以使用try{}catch(){}语句,而抛弃异常在方法声明是声明,在方法的声明后面加上throws XxxxException,抛弃多个异常时在各异常间使用逗号(,)分隔,题目中的程序在运行时抛出的不是一个RuntimeException,所有必须捕获或者抛弃,而程序又没有捕获,所有应该在方法声明中声明抛弃。由于Exception是所有异常的父类,所有当然也可以代表RuntimeException了。

  57、Which of the following answer is correct to express the value 10 in hexadecimal number?
  A. 0xA

  B. 0x16

  C. 0A

  D. 016

  (a)

  题目:下面的哪些答案可以正确表示一个十六进制数字10。

  十六进制数以0x开头,以0开头的是八进制数。十六进制表示中的a,b,c,d,e,f依次为10,11,12,13,14,15。

  58、Which statements about thread are true?
  A. Once a thread is created, it can star running immediately.

  B. To use the start() method makes a thread runnable, but it does not necessarily start immediately.

  C. When a thread stops running because of pre-emptive, it is placed at the front end of the runnable queue.

  D. A thread may cease to be ready for a variety of reasons.

(bd)

  题目:有关线程的哪些叙述是对的。

  A. 一旦一个线程被创建,它就立即开始运行。

  B. 使用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。

  C. 当一个线程因为抢先机制而停止运行,它被放在可运行队列的前面。

  D. 一个线程可能因为不同的原因停止(cease)并进入就绪状态。

  一个新创建的线程并不是自动的开始运行的,必须调用它的start()方法使之将线程放入可运行态(runnable state),这只是意味着该线程可为JVM的线程调度程序调度而不是意味着它可以立即运行。线程的调度是抢先式的,而不是分时间片式的。具有比当前运行线程高优先级的线程可以使当前线程停止运行而进入就绪状态,不同优先级的线程间是抢先式的,而同级线程间是轮转式的。一个线程停止运行可以是因为不同原因,可能是因为更高优先级线程的抢占,也可能是因为调用sleep()方法,而即使是因为抢先而停止也不一定就进入可运行队列的前面,因为同级线程是轮换式的,它的运行可能就是因为轮换,而它因抢占而停止后只能在轮换队列中排队而不能排在前面。

  59、The method resume() is responsible for resuming which thread's execution?

  A. The thread which is stopped by calling method stop()

  B. The thread which is stopped by calling method sleep()

  C. The thread which is stopped by calling method wait()

  D. The thread which is stopped by calling method suspend()

  (d)

  题目:方法resume()负责恢复哪些线程的执行。


A. 通过调用stop()方法而停止的线程。

  B. 通过调用sleep()方法而停止运行的线程。

  C. 通过调用wait()方法而停止运行的线程。

  D. 通过调用suspend()方法而停止运行的线程。

  Thread的API文档中的说明是该方法恢复被挂起的(suspended)线程。该方法首先调用该线程的无参的checkAccess() 方法,这可能在当前线程上抛出SecurityException 异常,如果该线程是活着的(alive)但是被挂起(suspend),它被恢复并继续它的执行进程。

  60、Given the following code:
  1) public class Test {

  2} int m, n;

  3} public Test() {}

  4} public Test(int a) { m=a; }

  5} public static void main(String arg[]) {

  6} Test t1,t2;

  7} int j,k;

  8} j=0; k=0;

  9} t1=new Test();

  10} t2=new Test(j,k);

  11} }

12} }
  Which line would cause one error during compilation?

  A. line 3

  B. line 5

  C. line 6

  D. line 10

  (d)

  题目:给出下面的代码:
  …
  在编译时哪行将导致一个错误。

  第10行的声明调用一个带两个参数的Test的构造方法,而该类没有这样的构造方法




用户名: 新注册) 密码: 匿名评论 [所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 2007年国家计算机等级考试 JAVA认证 JAVA真题 JAVA模拟试题
如果你觉得一篇文章有用,你可以在每篇后面参与评论,或者查看其他人的评论,请保证你的评论对大家友好。
点这里评论
或者您可以来资源论坛参与讨论,一切都是免费的,不过可能需要麻烦您注册一下。
点这里讨论
把你的文章登陆在这里,让大家来分享你的文章。请立即登陆发表!
点这里投稿