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);
}
}
}