package day01;
//构造函数
class Person1
{
private String name;
private int age;
Person1(){
System.out.println("name=" + name+ "age=" + age);
cry();
}
Person1(String n){
name = n;
System.out.println("B:name=" +name+",,age="+age);
cry();
}
Person1(String n,int a){
name = n;
age = a;
System.out.println("C:name="+name+",,age="+age);
cry();
}
public void cry(){
System.out.println("cry.....");
}
}
public class PersonDemo2 {
public static void main(String[] args){
Person1 p1 =new Person1();
Person1 p2 =new Person1("lala");
Person1 p3 = new Person1("lelel",10);
}
}
|
|