将内部内中要被调用的变量,方法设成public的,在外部类中new 一个内部类的实例直接调用就行了,
解决方案 »
- 求JAR包
- 新鲜出炉的用JAVA写的小游戏..点点世界V1.0发布!
- 请问如何把 SimpleThread.java中的所有线程修改成后台线程。 在线等。
- 高手请进:请教一个关于JDBC和多线程相关的问题
- serverlet中,怎样输出汉字到httprequest(就是用户的页面)中去呀?我的怎么全是乱码呀?
- 求救:JDBC-ODBC桥驱动程序新问题
- JBuilder7安装
- 1000baset用的是几对双绞线啊?
- 再问高手我的cloudscape的问题~急!
- 跨包之间访问protected类型的问题
- 软件学院的真实情况 ; 请个位在软件学院的同学回贴 ;)
- 如何知道鼠标离开了快捷菜单(JPopupMenu)?
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();
}
}
// 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");
}
}