class SetAgain
{
public static void main(String[] args)
{
System.out.println("Hello World!");
Person person=new Person();
person.setName("some body")
.setSex("male");
System.out.println(person);
}
}
class Person
{
String name=null;
String sex=null;
public Person()
{
name="unknow";
sex="unknow";
}
public Person(String name,String sex)
{
this.name=name;
this.sex=sex;
}
public Person setName(String name)
{
this.name=name;
return this;
}
public Person setSex(String sex)
{
this.sex=sex;
return this;
}
@Override
public String toString()
{
return "name:"+name+";sex:"+sex ;
}
}
/*
Hello World!
name:some body;sex:male
请按任意键继续. . .
*/
person.setName("some body") .setSex("male");
最新推荐文章于 2023-06-07 14:46:55 发布