public static void main(String[] args) {
People a=new People();
a.country="中國";
People b=new People();
System.out.println(b.country);
b.print();
a.p();
}
//static 修飾後的變量 靜态化 既不屬于棧記憶體,也不屬于堆記憶體
//可以說存放在 data 中 也叫共享區,方法區,資料區
/*
生命周期:
1.類變量生命周期最長,随着類的消失而消失
2.執行個體變量生命比類變量短,他是随着對象的消失而消失
方法注意事項:
1.靜态的方法隻能通路靜态的成員
2.非靜态的方法既能通路靜态成員(成員變量,成員方法)也能通路非靜态成員
3.靜态的方法中是不能定義this super 關鍵字的--因為靜态優先與對象的存在
*/
static class People{
String name;
int age; //執行個體變量
static String country; //靜态變量
static void print(){
String aa="你好";
System.out.println(aa);
}
void p(){
System.out.println(country);
}
}
}