//Final变量的几种初始化方法
public class FinalTest
{
//定义的时候初始化
final int a = 6;
final String str;
final static float b;
final double c;
//初始化块
{
str = "hello";
}
//静态初始化块
static
{
b = (float)5.6;
}
//构造函数
public FinalTest()
{
c = 4.5;
}
public static void main(String[] args)
{
FinalTest gg = new FinalTest();
System.out.println(gg.a);
System.out.println(gg.str);
System.out.println(gg.b);
System.out.println(gg.c);
}
}
final 成员变量初始化
最新推荐文章于 2022-04-27 10:29:57 发布