1.實例變量和類變量
成員變量 VS 局部變量
1 public class RightDef{
2 // 下面代碼完全沒有問題
3 int num1 = num2 + 20;
4 static int num2 = 10;
5 }
public class RightDef{
2 // 非法前向引用
3 int num1 = num2 + 20;
4 int num2 = 10;
5 }
public class RightDef{
2 // 非法前向引用
3 static int num1 = num2 + 20;
4 static int num2 = 10;
5 }
class Cat{
String name;
int age;
// 構造器中指定
public Cat(String name, int age){
this.name = name;
this.age = age;
}
// 非靜態代碼塊指定
{
weight = 2.0;
}
// 定義變量時指定
double weight = 2.3;
}
2.父類構造器
3.父子實例的內存控制
4.final修飾符