Sunday, 15 January 2017

Initialize final variable using constructer.


You can not initialize final variable. But it can only possible to initialize in constructor. Below example to initialize final variable.

package com.swain.sitansu;

public class Test {

private final String TEST;

public Test(String TEST) {
this.TEST = "Hello";//Initilize final variable using constructer
}

public static void main(String[] args) {
System.out.println(new Test("hello").TEST);
}

}

No comments:

Post a Comment