class Person
{
private String name;
private int age;
Person()
{
}
Person(String name)
{
this.name=name;
}
Person(String name,int age)
{
this(name);
this.age=age;
}
void speak()//定义一个输出语句的方法.
{
System.out.println(this.name+","+this.age)
}
}
class PersonDemo
{
public static void main(String[] args)
{
Person p= new Person("lisi",30);
p.speak();//用对象调用方法.
}
}
|