How this is code is getting compiled even though we are using a constant which is defined later?
- by GK
In the following code DEFAULT_CACHE_SIZE is declared later, but it is used to assign a value to String variable before than that, so was curious how is it possible?
public class Test {
public String getName() {
return this.name;
}
public int getCacheSize() {
return this.cacheSize;
}
public synchronized void setCacheSize(int size) {
this.cacheSize = size;
System.out.println("Cache size now " + this.cacheSize);
}
private final String name = "Reginald";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;
}