关于内部类写测试类的问题
package java1;public class Group4
{
public class Student1 //抽象内部类
{
int count;
String name;
public void output() {} //抽象方法
}
public class Student extends Student1//继承抽象内部类
{
public Student(String n1)
{
name = n1;
count++; //Student.count
}
public void output() //实现抽象方法
{
System.out.println(this.name +" count="+this.count);
}
}
[color=Red] /* public Group4()
{
Student s1 = new Student("A");
s1.output();
Student s2 = new Student("B");
s2.output();
}
public static void main (String args[])
{
Group4 g4 = new Group4();
}
} */[/color]
}
这是例题的源程序,其中红色的部分我想给它写到另外的一个测试类中,
package java1;
public class text {
public static void main(String[] args) {
Group4 g4 = new Group4();
[color=Cyan]Student s1,s2;[/color] }
}
但是蓝色的部分却报错,为什么?应该怎么改啊?
Group4.Student s1,s2;
Group4.Student s1=new Student("A");
s1.output();
或者帮我改一下这个!!
[[it] 本帖最后由 xiaolaba3330 于 2008-4-23 14:17 编辑 [/it]] Group4 group = new Group4();
Group4.Student s1=group.new Student("A");
都写成内部类了,何必这么麻烦还要到外面去实现呢。。。。。
回复 6# 的帖子
我是初学者,每个例题都想用各种方法练练手,熟悉一下!谢谢这位大侠了!!
页:
[1]
