Person(String name)
{
name = name;
//System.out.println("A:name="+name+",,age="+age); 加上这句话
//而主函数不调用speak就会有同样效果
}
public void speak()
{
System.out.println("name="+name+",,age="+age);
}
Person(String n,int a)
{
age = a;
name = n;
//System.out.println("C:name="+name+",,age="+age);
}
}
class Test09
{
public static void main(String[] args)
{
Person p =new Person("lisi");
Person p2 =new Person("wangwu",15);
Person p3 =new Person("zhangsan",16);
p.speak();
p2.speak();
p3.speak();
}
}作者: 叶久瑞 时间: 2012-8-9 19:06
this关键字
————————————————————————————————————————
class PersonDemo3 {
public static void main(String[] args) {
Person p1 = new Person(20);
Person p2 = new Person(25);
boolean b = p1.compare(p2);
System.out.println(b);
//Person p = new Person("lisi");
//Person p1 = new Person("zhangsan");
//p.speak();
//p1.speak();
//p.speak(); }
}
class PersonDemo4 {
public static void main(String[] args) {
new Person();
//Person p = new Person("lisi",30);
//Person p1 = new Person("lisi2",36); } }