Can a final variable be initialized when an object is created?

前端 未结 8 752
夕颜
夕颜 2020-12-09 10:29

how it can be possible that we can initialize the final variable of the class at the creation time of the object ?

Anybody can explain it how is it possible ? ...<

8条回答
  •  轮回少年
    2020-12-09 11:05

    Why not. Like this

    public class GenericFoo{
    
        final int var;
    
        GenericFoo(){
            var = 100;
        }
    
    }
    

提交回复
热议问题