将内部内中要被调用的变量,方法设成public的,在外部类中new 一个内部类的实例直接调用就行了,

解决方案 »

  1.   

    贴一段代码
    class Outer1{
    public class Inner{
    public void m1(int k){
    Outer2 outer2 = new Outer2();
    outer2.i = k;
    System.out.println("Outer2.i = "+outer2.i);
    }
    }
    }
    public class Outer2 {
    int i;
    void m2() {
    Outer1 outer = new Outer1();
    Outer1.Inner inner = outer.new Inner();
    inner.m1(1);
    } public static void main(String[] args) {
    Outer1 outer = new Outer1();
    Outer1.Inner inner = outer.new Inner();
    inner.m1(2);
    new Outer2().m2();
    }
    }
      

  2.   

    //: Parcel2.java
    // Returning a handle to an inner classpublic class Parcel2 {

    class Contents {
    private int i = 11;
    public int value() { return i; }
    }

    class Destination {
    private String label;
    Destination(String whereTo) {
    label = whereTo;
    }
    String readLabel() { return label; }
    }

    public Destination to(String s) {
    return new Destination(s);
    } public Contents cont() {
    return new Contents();
    }

    public void ship(String dest) {
    Contents c = cont();
    Destination d = to(dest);
    } public static void main(String[] args) {
    Parcel2 p = new Parcel2();
    p.ship("Tanzania");
    Parcel2 q = new Parcel2();
    // Defining handles to inner classes:
    Parcel2.Contents c = q.cont();
    Parcel2.Destination d = q.to("Borneo");
    }
    }
      

  3.   

    huanjing51(幻境) 的想法是对的