package lalala;
public class Person {
public String name="无名"; //昵称,默认为无名
public String sex="man"; //性别,默认值为man
public Person(){
this. name="王八";
this. sex="男";
}
public Person (String name){
this.name=name;
}
public Person (String name,String sex){
super();
this.name=name;
this.sex =sex;
}
public void print(){
System.out.println("Person的自白:\n我的昵称叫"+this.name+" ,性别是"+this.sex+"。");
}
}
/*
* 创建类的对象,并给属性赋值
*/
class TestSample{
public static void main(String[] args) {
Person person = new Person();
person.print();
person=new Person("李四");
person.print();
person=new Person("小李","女");
person.print();
}
}