java什么是最终变量_java中的最终变量 (Final variable in java)

2016-01-27 19:00:40

0

class Test {

public static final int x;

public static void main (String[] args) {

Test.x = 42;

}

}

I have declared a static final variable, and when i compiled it the following error shown up.

error: cannot assign a value to final variable x

Test.x = 42;

i think i have reached to the solution but i want to check if i am right or not?

I know that a static variable if not initialized is provided a default value. As it is a static final int variable it will be assigned a value of 0. later on, i tried to change the value to 42 which is not possible because the variable is final and cannot be changed from 0.

am i right or is there some other answer to it?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值