频道栏目
首页 > 资讯 > JAVA > 正文

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

16-06-07        来源:[db:作者]  
收藏   我要投稿
  例题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也正确

相关TAG标签
上一篇:JAVA认证历年真题:SCJP考试真题和解析3
下一篇:JAVA认证历年真题:SCJP考试真题和解析1
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站