class Demo1_Persom {
public static void main(String[] args) {
Person p = new Person();
p.name = "张三";
p.age = 23;
p.speak();
}
}
class Persom {
private String name;
private int age;
public void speak(){
System.out.println(name+" "+ age);
}
}
private成员变量name,age用set方法赋值,get方法调用吗?直接p.name,p.age怎么也能赋值? |
|