public class Test {
class Student{
public String name;
public int age;
public int score;
Student(String n,int a,int s)
{
name = n;
age = a;
score = s;
System.out.println(name="+name",age="+age",score="+score");
}
}
class Student2
{
public void main(String[] args)
{
Student p =new Student("zhangsan",22,25);
}
}
看了毕老师的视频,各位帮我看看这段代码哪里有问题啊 作者: 小冰块 时间: 2013-8-24 16:01
你的Student被定义成了一个内部类!就是在class Test这个类里面的一个类。这样当然没法用,你只需要留下一个类就行了。作者: xuluheng718 时间: 2013-8-24 16:04
你的Student是Test的内部类吗?假如是的话,
那么要产生内部类实例,要这样写:
Test.Student p = new Test().new Student("zhangsan",22,25);
还有就是你的Test类少了个括号,还有你的Student的构造方法里面的打印语句要改为:
System.out.println("name="+name+",age="+age+",score="+score);作者: xinchenglong 时间: 2013-8-24 16:04
貌似你的链接字符串有问题吧!!为什么不用占位符的形式呢?这是一个很简单的构造函数,直接输出就ok了,好好检查一下!作者: xscn 时间: 2013-8-24 16:08
System.out.println(name="+name",age="+age",score="+score");里面能这么写吗??
类也定义的多余,没必要有student2这个类,test这个类做什么的?
给你改下,你对比下