初始化对象时构造函数如何工作?
2022-09-03 16:38:05
此代码的输出为 7 20。
为什么7首先打印,20之后打印?
public class Television
{
private int channel = setChannel(7);
public Television(int channel)
{
this.channel = channel;
System.out.print(channel +"");
}
public int setChannel(int channel)
{
this.channel = channel;
System.out.print(channel + "");
return channel;
}
public static void main(String args[])
{
new Television(20);
}
}