SCJP考试练习题3

11.Which statement of assigning a long type variable to a hexadecimal value is correct? 
A. long number = 345L;
B. long number = 0345;
C. long number = 0345L;
D. long number = 0x345L 
答案:D

分析:16进制以“0x”开头,8进制以“0”开头;long型数以L(大小写均可,一般使用大写,因为小写的l和数字1不易区分)。

 

--------------------------------------------------------------------

12.  Which of the following fragments might cause errors? 

A. String s = "Gone with the wind";
   String t = " good ";
   String k = s + t;

B. String s = "Gone with the wind";
   String t;
   t = s[3] + "one";

C. String s = "Gone with the wind";
   String standard = s.toUpperCase();

D. String s = "home directory";
   String t = s - "directory";

答案:BD

分析:String是java的一个类,只有“+”操作,没有“-”的操作;String类不能想数组一样使用下标[i]来进行操作;toUpperCase()方法是将文字转化为大写,并返回String。

 

--------------------------------------------------------------------

13.Which are syntactically valid statement at// point x? 

class Person {
private int a;
public int change(int m){ return m; }
}

public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}

A. i = m;
B. i = b;
C. i = p.a;
D. i = p.change(30);
E. i = t.b. 
答案:DE

分析:A:m没有被申明过,不能使用。
B:虽然b是类Teacher的public成员变量,但是在静态方法中不能使用类中的非静态成员。
C:a是类Person的private成员,在类外不能直接引用。
D:change(int m)方法是public方法,并且返回一个int型值,可以通过类的实例变量p引用并赋值给
   一个int型变量。
E:b是类Teacher的public成员变量,且是int型,可以通过类的实例变量t引用并赋值给一个int型变量。

 

--------------------------------------------------------------------------

14.Which layout manager is used when the frame is resized the buttons's position in the 
 Frame might be changed? 

A. BorderLayout
B. FlowLayout
C. CardLayout
D. GridLayout
答案:B

分析:A:该布局管理器将容器划分为五个部分,容器大小的改变不会影响其中的组件的位置而是影响他们的
   大小。
B:该布局管理器根据放入其中的组件的最合适大小调整组件的位置,根据组件放入的顺序安排,一行
   不能容纳时放入下一行,因此容器的大小改变可能改变组件的位置。
C:该布局管理器显示放入该容器的当前页中的组件,一次显示一个,容器大小的改变不能影响其中组
   件的位置。 
D:该布局管理器将容器划分为固定的网格,组件加入后占据一个单元,各组件的相对位置不会因为容
   器的大小变化而变化,改变的只是组件的大小。 

 

-------------------------------------------------------------------------

15.Given the following code fragment:
1) public void create() {
2} Vector myVect;
3} myVect = new Vector(); 
4} }

Which of the following statements are true? 
A. The declaration on line 2 does not allocate memory space for the variable myVect.
B. The declaration on line 2 allocates memory space for a reference to a Vector object.
C. The statement on line 2 creates an object of class Vector.
D. The statement on line 3 creates an object of class Vector.
E. The statement on line 3 allocates memory space for an object of class Vector 

答案:ADE

分析:要为一个新对象分配空间必须执行new Xxx()调用,new调用执行以下的操作:
1.为新对象分配空间并将其成员初始化为0或者null。
2.执行类体中的初始化。(例如在类中有一个成员声明int a=10;在第一步后a=0 ,执行到第二步后 a=10)
3.执行构造函数。
4.变量被分配为一个到内存堆中的新对象的引用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值