SUN认证Java2程序员考试(SCJP)试题解析


作者: | 来源:考龙网 | 日期:06-28 | 字体: [ ]

本文简介:Java是一种纯粹的面向对象的程序设计语言。在正式使用Java做开发之前,必须将我们的思维方式转入一个彻底的面向对象的世界


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



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

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