class Person
{
private String name;
private int age;
Person()
{
name = "baby";
age = 1;
System.out.println("person run");
}
Person(String name)
{
this();
this.name = name;
}
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public void speak()
{
System.out.println(this.name+":"+this.age);
}
/*
判断是否是同龄人。
*/
public boolean compare(Person p)
{
/*
if(this.age==p.age)
return true;
else
return false;
*/
return this.age==p.age;
}
}
class ThisDemo
{
public static void main(String[] args)
{
Person p1 = new Person("aa",30);//
Person p2 = new Person("zz",12);
p2.compare(p1);为何在命令行运行之后没有结果呢?
|
|