我在学内部类,我看的那些教程看不懂,
根本不知道内部类是什么东西。
请问
内部类要怎样学啊,能举一些的例吗?谢谢。。。。
[此贴子已经被作者于2006-10-18 23:33:20编辑过]
public class Group4
{
public abstract class Student_abstract //抽象内部类
{
int count;
String name;
public abstract void output(); //抽象方法
}
public class Student extends Student_abstract //继承抽象内部类
{
public Student(String n1)
{
name = n1;
count++; //Student.count
}
public void output() //实现抽象方法
{
System.out.println(this.name +" count="+this.count);
}
}
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();
}
}
public class Group5
{
public interface Student_info //内部接口
{
public void output();
}
public class Student implements Student_info //内部类实现内部接口
{
int count;
String name;
public Student(String n1)
{
name = n1;
count++;
}
public void output() //实现接口方法
{
System.out.println(this.name +" count="+this.count);
}
}
public Group5(String name1[])
{
Student s1;
int i=0;
while (i<name1.length)
{
s1 = new Student(name1[i]);
s1.output();
i++;
}
}
public static void main (String args[])
{
Group5 g5;
if (args.length>0)
g5 = new Group5(args);
}
}