“你好，阿米戈！今天，比拉博会谈论变量初始化的顺序。”

``````class Cat
{
public int a = 5;
public int b = a + 1;
public int c = a * b;
}``````

``````class Cat
{
public int a = getSum();
public int b = getSum() - a;
public int c = getSum() - a - b;

public int getSum()
{
return a + b + c;
}
}``````

“真的允许吗？”

“当然。声明类的成员方法和字段的顺序并不重要。

“结果会怎样？”

“创建变量时，它们将获得默认值。”

``````class Cat
{
public int a = 5;
public int b = a + 1;
public int c = a * b;
}``````
``````class Cat
{
public int a = 0;
public int b = 0;
public int c = 0;

public Cat()
{
super();

a = 5;
b = a + 1; //5+1 = 6
c = a * b; //5*6 = 30
}
}``````
``````class Cat
{
public int a = getSum();
public int b = getSum() - a;
public int c = getSum() - a - b;

public getSum()
{
return a + b + c;
}
}``````
``````class Cat
{
public int a = 0;
public int b = 0;
public int c = 0;

public Cat()
{
super();

a = getSum(); //(a+b+c)=0
b = getSum() - a; //(a+b+c)-a=b=0
c = getSum() - a - b; //(a+b+c)-a-b=c=0
}

public getSum()
{
return a + b + c;
}
}``````

“天哪！这么简单。谢谢你，比拉博。你真够朋友！”

“太棒了！比拉博终于交了个朋友！”