I'm learning java and accidentally I came across following code where default constructor is executed after the method.
public class ChkCons { int var = getVal(); ChkCons() { System.out.println("I'm Default Constructor."); } public int getVal() { System.out.println("I'm in Method."); return 10; } public static void main(String[] args) { ChkCons c = new ChkCons(); } }
OUTPUT :
I'm in Method. I'm Default Constructor.
Can anyone please explain me why this happened?
Thanks.