public class InnerClassDemo {
class Student{
void print(){
System.out.println("This is an inner class as an instance variable");
}
}
void classInAmethod(){
class Son{
void print(){
System.out.println("I am within a method");
}
}
Son s = new Son();
s.print();
}
public static void main(String[]args){
InnerClassDemo is = new InnerClassDemo();
is.classInAmethod();
InnerClassDemo.Student s = is.new Student();
s.print();
}
}
資料來源:http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html
相關文章:anonymous class
沒有留言:
張貼留言