JAVA认证历年真题:SCJP考试真题和解析(1)

来源:java认证发布时间:2012-11-12 13:05:45java认证视频

  例题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也正确。

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答