public class Sample {
{
//System.out.println("Value of k is "+k);Illegal forward reference.
System.out.println("Value of a is "+getA());
}
//int i=j;Illegal forward reference.
int k=getJ();
int j=10;
public static void main(
String[] args) {
System.out.println("Welcome to the real world."+new Sample().k);
}
public int getJ() {
return j;
}
public int getA() {
return a;
}
int a=10;
}
Output of the above program is
Value of a is 0
Welcome to the real world.0
------------------------------------------------
But, I thought it would be 10 for both as shown below.
Value of a is 10
Welcome to the real world.10
I was wrong can somebody explain why ?
Thanks!!