class Person{
String name;
static char sex;
}
public class Study{
public static void main(String[] args){
Person one=new Person();
one.name="哈哈";
one.sex='男';
Person two=new Person();
System.out.println(two.sex);
}
}
输出结果为
男
——static 修饰符用途之一
当某类的对象有同样的属性值时,在创类文件中将其加上static修饰符,只要主程序中此类的任意一个对象拥有此值时,此类的其他对象也将拥有这个属性值。(即共享数据)
这个值,存在于内存的静态区(datesegment)
(内存共4个区-栈区,堆区,静态区(共享区),代码区)
ps:今天饭局喝多了,就学这么点了,洗澡睡觉