package oop.Demon10;
public class Outer {
private int id=10;
public void out(){
System.out.println("这是外部类的方法");
}
public class Inner{
public void in(){
System.out.println("这是内部类的方法");
}
//或得外部类的私有属性
public void getID(){
System.out.println(id);
}
}
}
==========================
package oop;
import oop.Demon10.Outer;
public class Application {
public static void main(String[] args) {
//new
Outer outer = new Outer();
//通过这个外部类来实现内部类
Outer.Inner inner = outer.new Inner();
inner.getID();
}
}
网友评论