class Person
{
private String name;
private int age;
Person(String name,int age)
{
name=name;
age=age;
speak();
}
public void speak()
{
System.out.println("name="+name+" "+"age="+age);
}
}
class PersonTest
{
public static void main (String [] args)
{
Person p=new Person("zhangsan",10);
}
}
---------------------------------------------------------------------------------------------------------------------
class Person
{
private String name;
private int age;
Person(String name,int age)
{
name=name;
age=age;
System.out.println("name="+name+" "+"age="+age);
}
}
class PersonTest
{
public static void main (String [] args)
{
Person p=new Person("zhangsan",10);
}
}
为什么第一个初始化失败,第二个ok? |
|