JAVA认证历年真题:SCJP考试真题和解析(1)
来源:优易学  2011-9-22 19:41:05   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  例题4:

  Which of the following lines of code will compile without error?

  A.
  int i=0;
  if (i) {
  System.out.println(“Hi”);
  }

  B.
  boolean b=true;
  boolean b2=true;
  if(b==b2) {
  System.out.println(“So true”);
  }

  C.
  int i=1;
  int j=2;
  if(i==1|| j==2)
  System.out.println(“OK”);

  D.
  int i=1;
  int j=2;
  if (i==1 &| j==2)
  System.out.println(“OK”);

  解答:B, C

  点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有^、&、| 和 &&、||,但是“&|”是非法的,所以选项D不正确。

  例题5:

  Which two demonstrate a "has a" relationship? (Choose two)

  A. public interface Person { }

  public class Employee extends Person{ }

  B. public interface Shape { }
  public interface Rectandle extends Shape { }

  C. public interface Colorable { }
  public class Shape implements Colorable
  { }

  D. public class Species{ }
  public class Animal{private Species species;}

  E. interface Component{ }
  class Container implements Component{
  private Component[] children;
  }

  解答:D, E

  点评: 在Java中代码重用有两种可能的方式,即组合(“has a”关系)和继承(“is a”关系)。“has a”关系是通过定义类的属性的方式实现的;而“is a”关系是通过类继承实现的。本例中选项A、B、C体现了“is a”关系;选项D、E体现了“has a”关系。

  例题6:

  Which two statements are true for the class java.util.TreeSet? (Choose two)
  
  A. The elements in the collection are ordered.

  B. The collection is guaranteed to be immutable.

  C. The elements in the collection are guaranteed to be unique.

  D. The elements in the collection are accessed using a unique key.
  E. The elements in the collection are guaranteed to be synchronized
  解答:A, C

  点评:TreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项A也正确。

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训