How this is code is getting compiled even though we are using a constant which is defined later?
Posted
by GK
on Stack Overflow
See other posts from Stack Overflow
or by GK
Published on 2010-03-21T17:13:19Z
Indexed on
2010/03/21
17:21 UTC
Read the original article
Hit count: 359
java
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;
}
© Stack Overflow or respective owner