public class Person { private String name; private int age;

public Person(String name, int age){
	this.name = name;
	this.age = age;
}

public void display(){
	System.out.println('Name: ' + name + '    Age: ' + age);
}

public String getName(){
	return name;
}

public void setName(String name){
	this.name = name;
}

public int getAge(){
	return age;
}

public void setAge(int age){
	this.age = age;
}

public static void main(String[] args) {
	Person p = new Person('张三', 20);
	p.display();
	
	p.setName('李四');
	p.setAge(25);
	
	System.out.println('Updated Name: ' + p.getName() + '    Updated Age: ' + p.getAge());
}

}


原文地址: https://www.cveoy.top/t/topic/ph5o 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录