You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
edu/新建 文本文档 (1).txt

45 lines
889 B

张三 18
package case1;
public class TestPersonDemo {
public static void main(String[] args) {
/********* begin *********/
// 声明并实例化一Person对象p
Person p1=new Person();
// 给p中的属性赋值
String name=p1.getName();
name="张三";
p1.setName(name);
int age=p1.getAge();
age=18;
p1.setAge(age);
// 调用Person类中的talk()方法
p1.talk();
/********* end *********/
}
}
// 在这里定义Person类
class Person {
/********* begin *********/
private String name;
private int 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 void talk(){
System.out.println("我是:"+name+",今年:"+age+"岁");
}
/********* end *********/
}