/*
构造函数练习
*/
class PersonDome
{
public static void main(String[] a)
{
Person p0=new Person();
Person p1=new Person(100);
Person p2=new Person(10,"lisi");
System.out.println("第二个人的年龄 "+p1.age);
}
}
class Person
{
int age;
String name;
Person()
{
speak();
}
Person(int age)
{
this.age=age;
speak();
}
Person(int a,String s)
{
age=a;
name=s;
speak();
}
void speak()
{
System.out.println("name="+name+" age="+age);
}
void cry()
{
System.out.println("cry.......");
}
}
|
|