首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 计算机考试 > 认证考试 > JAVA认证 >

SCJP认证套题解析之五

2008-10-05 
   void printvalue(int m){    do { system.out.println("the value is" m)    }    ...

   void printvalue(int m){
   do { system.out.println("the value is" m);
   }
   while( --m > 10 )
   }
   public static void main(string arg[]) {
   int i=10;
   test t= new test();
   t.printvalue(i);
   }
   }
   which will be output?
   a. the value is 8
   b. the value is 9

   c. the value is 10

   d. the value is 11

   (c)

   题目:给出下面的代码:
   …
   输出将是什么?

   此题考察的是do… while循环和 -- 操作符的知识,do…while最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内容,然后再进行判断,以此类推直到while的判断为false时退出循环执行循环后面的内容,而—操作符的规则是在变量右边的-- 将先进行运算,然后才是使变量的值减一,而在变量左边的是先将变量的值减一再运算

21、which of the following assignment is not correct?


   a. float f = 11.1;
   b. double d = 5.3e12;

   c. double d = 3.14159;

   d. double d = 3.14d.

   (a)

   题目:下面的哪些赋值语句是对的。

   浮点数的赋值是带有小数点的数字缺省是double型的,如果在浮点数后面加f或者f则是float,后面加d或者d则是double,科学计数法形式的浮点数也是double型的,而double的精度比float高,将一个高精度的double赋值给一个低精度的float时需要进行强制类型转换,反之则不需要。


   22、given the uncompleted code of a class:
   class person {
   string name, department;
   int age;
   public person(string n){ name = n; }
   public person(string n, int a){ name = n; age = a; }
   public person(string n, string d, int a) {
   // doing the same as two arguments version of constructor
   // including assignment name=n,age=a
   department = d;
   }
   }
   which expression can be added at the "doing the same as..." part of the constructor?

   a. person(n,a);

   b. this(person(n,a));

   c. this(n,a);

   d. this(name,age).

   (c)

   题目:给出下面的不完整的类代码:
   …
   下面的哪些表达式可以加到构造方法中的"doing the same as..."处?

   在同一个类的不同构造方法中调用该类的其它构造方法需要使用this(…)的形式,而且必须是在构造方法的第一行调用,这个和普通的方法重载调用的方式不同,普通的方法可以直接使用方法名加参数来调用,而且调用位置没有限制,因此答案a是不行的,b的语法就是错误的,d的错误在于在父类型的构造函数被调用前不能引用类的成员。构造方法是一个类对象实例化的起点(虽然严格来说首先执行的并不是构造方法的第一个语句,而是内存的分配),因此在构造方法中不能将成员作为参数引用。

   23、which of the following statements about variables and their scopes are true?

   a. instance variables are member variables of a class.

   b. instance variables are declared with the static keyword.

   c. local variables defined inside a method are created when the method is executed.

   d. local variables must be initialized before they are used.
  (acd)

   题目:下面关于变量及其范围的陈述哪些是对的。

   a. 实例变量是类的成员变量。

   b. 实例变量用关键字static声明。

   c. 在方法中定义的局部变量在该方法被执行时创建

   d. 局部变量在使用前必须被初始化。

   类中有几种变量,分别是:局部变量(英文可以为:local\automatic\temporary\stack variable)是定义在方法里的变量;实例变量(英文为:instance variable)是在方法外而在类声明内定义的变量,有时也叫成员变量;类变量(英文为:class variable)是用关键字static声明的实例变量,他们的生存期分别是:局部变量在定义该变量的方法被调用时被创建,而在该方法退出后被撤销;实例变量在使用new xxxx()创建该类的实例时被创建,而其生存期和该类的实例对象的生存期相同;类变量在该类被加载时被创建,不一定要用new xxxx()创建,所有该类的实例对象共享该类变量,其生存期是类的生存期。任何变量在使用前都必须初始化,但是需要指出的是局部变量必须显式初始化,而实例变量不必,原始类型的实例变量在该类的构造方法被调用时为它分配的缺省的值,整型是0,布尔型是false,而浮点型是0.0f,引用类型(类类型)的实例变量的缺省值是null(没有进行实际的初始化,对它的使用将引起nullpointexception),类变量的规则和实例变量一样,不同的是类变量的初始化是在类被加载时。

   24、public void test() {
   try { onemethod();
   system.out.println("condition 1");
   } catch (arrayindexoutofboundsexception e) {
   system.out.println("condition 2");
   } catch(exception e) {
   system.out.println("condition 3");
   } finally {
   system.out.println("finally");
   }

  }
   which will display if onemethod run normally?
   a. condition 1

   b. condition 2

   c. condition 3

   d. finally

   (ad)

   题目:在onemethod()方法运行正常的情况下将显示什么?

   如果try块中的语句在执行时发生异常,则执行从该处中断而进入catch块,根据异常的类型进行匹配,最前面的优先进行匹配比较,只要该异常是catch中指定的异常的子类就匹配成功进而执行相应的catch中的内容,而finally块中的内容无论是否发生异常都将被执行。

   25、given the following code:
   public class test {