SCJP---Chap01

Q1:What will happen when you try to compile and run the following program?

 

 Select the right answer:

   A. THe code compiles and displays "mpg:50" if the command-line argument is "Highway".If the command-line argument is not "Highwas",the code display "mpg:25";

   B. The code compiles and displays "mpg:25" if the command-line argument is "Highway".If the command-line argument is not "Highway",the code throws an arrayIndexOutOfBoundsException.

   C. The code does not compile because the automatic variable named index has not been initialized.

   D. The code does not compile because milesPerGallon has not been initilized.

  E. The code does not compile because the no-args constructor is not written correctly.

Answer:C.

如果是类成员变量,则自动会被初始化。如果是方法的局部变量,是不会被编译器自动初始化的。所以在访问数族元素时,由于索引值未被指定,因此编译无法通过。

其实编译器首先会报Cannot make a static reference to the non-static field milesPerGallon.将if的body注释掉后,会报“The local variable index may not have been initialized.”

 

Q2: How you can use the escape notation /u to set the variable c, declared as a char ,to the Unicode character whose value is hex 0x30A0;

 

????????

Q3: Which label names are illegal?

   A. there;

   B. here

   C. this

   D. that

   E 2total;

Answer:C,E

标识符只能以字母,$或下划线开头,随后的字符可以是字母,$,下划线或数字。

Q4:What will happen when you attempt to compile and run the following program by passing the Test Class to the Java Interpreter?

Select the one right answer:

   A. The program does not compile because main() is not defined correctly.

   B. The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.

   C. The program compiles but you cannot run it because the class is not declared as public.

   D. The program compiles and runs without an error but does not display anything in the standard output.

   E. The program compiles and displays "hello" in the standard output when you run it.

Answer: B

   When you run it ,the system will turn a error:Exception in thread "main" java.lang.NoSuchMethodError: main.

Q5:Which statements about garbage collection are true?

Select all valid answers.

   A. You can directly free the memory allocated by an object.

   B. You can directly run the garbage collector whenever you want to.

   C. The garbage collector informs your object when it is about to be garbage collected.

   D. The garbage collector reclaims an object's memory as soon as it becomes a candidate for garbage collection.

   E. The garbage collector runs low-memory situations.

Answer: B, C, E

   B:可以将某个引用设为null,调用Runtime或System类的gc()方法来运行垃圾回收站。

   C:finalize()方法会在gc进行来及回收时被调用。

Q6:What output produced by the following program?

Select the one right answer:

   A. A compiler error

   B. A runtime error

   C. 10

   D. 20

Answer: A

    Java 规定只能用byte,short(短整型),int来指定数组类型,而不能是long(长整型)。

Q7: True or false?Element value in Java arrays are automatically initialized when the array is constructed using the new operator.

Answer: True

    数组中不同类型元素的初始值如下:

    对象(reference): null

    char:'/u0000'

Q8: When an array of char elements is constructed,the elements are automatically initalized to which of the following values:

A '0'

B '/u0000'

   字符型值是一个无符号整数值,其初始化为0,即4个16进制的数。

Q9:What output is produced by the following program?(Note the placeholder comma is the boldface portion)

   A. a compile error

   B. a runtime error

   c. 0

   datetype[] arr = {data1,data2.....}

   如果采用指定初始化的方式,必须提供所有元素的初始化值,而不能使用两个逗号来希望自动初始化对应位置的元素。

Q10:Show 6 different ways to express the decimal value 28 as a integral literal:

Q11:There are seven characters,at least one of which must be included to indicate a floating point literal.What are they?

    d, D, f, F, e, E

     科学技术法:4.23E+12,4.23e+12

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值