java类中访问属性

时间:2022-08-25 08:29:46
package first;

public class for_protect {
private int age=10;
int number = 100;
public void show(){
System.out.println(number);
System.out.println(this.number=1000);
System.out.println(this.number);
//private的变量用this
//static变量用类名.变量
//public 直接表示或this.number
}
public static void main(String args[]){
for_protect test = new for_protect();
test.show();
}
}