[英]how to access members of a static inner class from main method of different class
堆栈溢出只是想让我在这里写更多。
Class A{
static Class B{
int i,j;
}
B method(int x){
// how to return object of type B
}
}
Class Main(){
// how do i call method B here
}
如果Main和A在同一个包中,这应该已经按如下方式工作:
A.java:
class A {
static Class B{
int i,j;
}
B method(int x){
// how to return object of type B
return new B();
}
}
主.java:
public class Main {
public static void main(String[] args) {
// how do i call method B here
A a = new A();
A.B b = a.method();
}
}
如果它们在单独的包中,您需要将类 A 和 B 声明为 public。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.