本帖最后由 叶绍亮 于 2012-3-16 22:01 编辑
class Student
{
private String name;
private int age;
private int num;
Student(String n,int a,int b)
{
name=n;
age=a;
num=b;
out();
}
void out()
{
System.out.println("姓名:"+name+",年龄:"+age+",成绩:"+num);
}
}
class StudentDemo
{
public static void main(String[] args)
{
Student p1 = new Student("lisi",10,56);
Student p2 = new Student("wangwu",23,65);
}
}
上面的可以运行,下面这样的就不行 ,原理是什么?不明白啊。请教啊。
class Student
{
private String name;
private int age;
private int num;
Student(String n,int a,int b)
{
name=n;
age=a;
num=b;
}
void out()
{
System.out.println("姓名:"+name+",年龄:"+age+",成绩:"+num);
}
}
class StudentDemo
{
public static void main(String[] args)
{
Student p1 = new Student("lisi",10,56);
Student p2 = new Student("wangwu",23,65);
p3.out();
}
} |
|