[英]referencing method in the inner class from the outer class
我有下面的代码,尽管类和成员方法是公共的,但我无法在methodLMF内引用methodHF而不是methodBF。 我尝试了以下方法:
LMF.this.xxxx //but the methods do not show up
请告诉我如何解决。
代码 :
class LMF {
LMF() {}
public methodLMF() { } // should return methodHF+methodBF
//class HF
class HF {
HF() {}
public methodHF(int x) {x++}
}
//class BF
class BF {
BF() {}
public methodBF(int x) {x++}
}
}
您需要创建HF和BF的对象才能访问其中的方法。
class LMF {
LMF() {
}
public int methodLMF(int x) {
return new HF().methodHF(x) + new BF().methodBF(x);
} // should return methodHF+methodBF
// class HF
class HF {
HF() {
}
public int methodHF(int x) {
return x++;
}
}
// class BF
class BF {
BF() {
}
public int methodBF(int x) {
return x++;
}
}
public static void main(String[] args) {
System.out.println(new LMF().methodLMF(1));
}
}
您需要以以下身份访问它
HF hF = this.new HF(); hF.methodHF()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.