Sun - Java程序员认证考试题库 下载本文

内容发布更新时间 : 2024/11/5 13:36:51星期一 下面是文章的全部内容请认真阅读。

8.我们定义一个Account类来描述银行账户,银行账户有账户名、金额等属性

特征,同时有存款、取款等行为特征,下述代码适合描述的是哪项? A.class Accountf String name;//账户 String amount; //金额 Account (String name)( )

void deposit (double mount){ //存款 )

void withdraw (double mount){ //取款 } )

B.class Accountf String name;//账户

doujole amount; //金额 Account (double amount){ )

void deposit (double mount){ //存款 )

void withdraw (double mount){ //取款 ) )

C.class Accountf String name;//账户

double amount; //金额 Account (String name){ )

void deposit (double mount){//存款 )

void withdraw (double mount){ //取款 ) )

D.class Accountf String name;//账户 double amount;//金额 Account (String name){ ) void deposit(){//存款 )

void withdraw(){//取款 ) )

1-21

9.现有:

1. class Banana2 f 2. static int X=2;

3.'public static void main (String [] args) { 4. int X=2;

5.Banana2 b=new Banana2(); 6. b.go(x); 7. }

8. static {x+=x; ) 9. void go (int x) { 10. ++x;

11. System. out.println (x); 12. } 13. } 结果为: A.7 B. 5 C. 3 D. 2

10.现有:

1. class TestFoo f 2. int x;

3. String y;

4.int getX() { return x; } 5.String getY() {return y; } 6. void setX (int x) { 7. int Z=7: 8. this.x=x; 9. } 10. }

可以添加多少个修饰符来封装此类? A.5 B. 4 C. 3 D. 2

1-22

11.定义枚举如下:

public enum Direction{ EAST,SOUTH,WEST,NORTH )

F列正确使用该枚举类型的语句是哪项? A. Direction Direction=EAST;

B. Direction direction=Direction.WEST; C. int a- Direction.NORTH; n Direction direction=2;

12.定义类: package utils; public class Rep{

public static String twice (String s){return s+s ;) }

再定义另一个类Demo: l.//insert code here 2.public class Demo{

3. public static void main (String[] args){ 4.System. out .println( twice( \ 5. } 6.}

在第一行插入哪项代码,可以使程序正常编译和执行? A.import utils.*; B. import utils.Rep.*;

C. import static utils.Rep.twice; D. static import utils.Rep.twice;

13.现有:

public class TestDemo{ private int X-2; static int y=3;

public void method(){ final int i=100; int j =10; class Cinner {

public void mymethod(){ //Here } } } }

1-23

在Here处可以访问的变量是哪些?(选三项) A.X B. y C. j D. i

14.现有如F包结构: com |一一X

| |一一Alpha.class | |

| |一一y

I |一一Beta.class |

|l-- Gamma.class 和类:

class Test { Alpha a; Beta b; Gamma c; }

哪三个必须加入到类Test中,以使其通过编译?(选三项) A. package y; B. package com; C. import com.x.y.*; D. import com.x.*;

15.现有2个文件: 1.package x; 2. public class X{

3.public static void doX() {System.out.print(\ 4. } 和:

1. class Find{

2.public static void main(String [] args) { 3. //insert code here 4. } 5. }

哪两行分别插入到类Find的第3行将编译并产生输出“doX”?(选两项)

A.doX();

B. X.doX(); C.x.X.doX();

D. x.X myX=new x.X();myX.doX();

1-24

1D 2A 3C 4C 5A 6C 7 ACD 8C 9C 10 D 11 B 12 C 13 A B D 14 BCD 15 C D

1-25