+ 2
Can we initialise final variable using constructor
validation of final keyword
1 Answer
+ 5
Yes, once final member is set it cannot be changed though.
class Test {
private final int NUM;
Test(int num) {
this.NUM = num;
}
public int getNum() {
return NUM;
}
}
public class Program
{
public static void main(String[] args) {
Test t = new Test(5);
System.out.println(t.getNum());
}
}