I am not able to understand flow of control in the following code:
class Television {
private int channel=setChannel(7);
public Television (int channel) {
this.channel=channel;
System.out.println(channel + "");
}
public int setChannel(int channel) {
this.channel=channel;
System.out.print(channel + " ");
return channel;
}
}
public class TelevisionMain {
public static void main(String[] args) {
Television t = new Television(12);
}
}
The output is 7 12.
It means explicit invocation occurs first. I am new to java and I thought that execution starts from main so the constructor should have been invoked first. Can anyone please explain why this happens.