this方法赋值、构造方法赋值
public class person(){
private String name;
private int age;
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public void getName(){
return name;
}
public void getAge(){
return age;
}
public void fuzhi(){ //public void fuzhi(String name,int age) //带参数赋值与方法内赋值
this.name = " ABC"; //this.name = name;
this.age=15; //this.age = age;
}
//构造方法赋值、
public person(){
name
}
}
Test:
public class test {
public static void main(String[] args) {
person p = new person();
p.fuzhi();
// p.fuzhi("FGB",20);
}