java习题

 

2.1.  Given:

1. enum Animals{

2.   DOG(“woof”),CAT(“meow”),FISH(“burble”);

3.   String sound;

4.   Animal(String s){ sound = s;}

5. }

6. class TestEnum{

7.    static Animal a;

8.    public static void main(String[] args){

9.     System.out.println(a.DOG.sound +” ” +a.FISH.sound);

10.    }

11. }

What is the result?

A. woof burble

B. Multiple compilation errors

C. Compilation fails due to an error on line 2

D. Compilation fails due to an error on line 3

E. Compilation fails due to an error on line 4

F. Compilation fails due to an error on line 9

提示:枚举可以有构造方法和变量

 

 

3.1. Given the following code:(构造方法)

 

what is the result? Select all right answer:

A. Hello

B. Hello World

C. Compilation fails

D. Hello World 5

E. The code runs with no output

F. An exception is thrown at runtime

C考查构造器之间的调用,通过this关键字实现构造器的调用. 在同一个类的不同构造器中调用该类的其他构造器需要使用this(…)的形式,而且必须是在构造器的第一行调用.在本示例中,类Hello中存在两个构造器,一个带参数,一个无参数,再带参数的构造器中试图通过Hello()调用无参构造器导致编译错误.

如果将Hello()改为this()语句如果不放在第一行也会导致编译错误

 

When  //doStuff is reached, how many objects are eligible for GC?

A. 0

B. 1

C. 2

D. Compilation fails

E. It is not possible to know

F. An exception is thrown at runtime

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值