package ctgu.java;
public class TestPerson1 {
public static void main(String[] args) {
//Person p1 = new Person();
String str = new String ("ctgu.com");
System.out.println(str);
Person p2 = new Person("佳莹");
Person p1= new Person();
System.out.println(p1.getName()+":"+p1.getAge());
System.out.println(p2.getName());
System.out.println(p2.getAge());
Person p3=new Person("李靳",23);
System.out.println("name:" + p3.getName()+"age:"+p3.getAge());
}
}
class Person{
private String name ;
private int age ;
public Person(String n){
name = n ;
}
public Person(){
age = 10;
name = "张三";
}
public Person(String n,int a){
name = n;
age = a ;
}
public void setName(String n){
name = n;
}
public void setAge(int a ){
age = a ;
}
public String getName(){
return name ;
}
public int getAge(){
return age ;
}
}
转载于:https://blog.51cto.com/9815936/1604910