class Person
{
String name;
int age;
/*
public void eat()
{
//System.out.println("年龄:"+p2.age);
//System.out.println("姓名:"+p2.name);
System.out.println("正在吃饭!");
}
*/
}
public class Test
{
public static void main(String[] args)
{
Person p1 = null;
Person p2 = null;
p1 = new Person();
//p1.eat();
p1.name="李四";
p1.age= 23;
p1=p2;
System.out.println("姓名:"+p2.name);
System.out.println("年龄:"+p2.age);
p1=null;
}
}
运行这个程序时出现了空指针异常,本人新手求高手来解答。 |