对象方法可以通过以下方式引用该对象的内部类:
public class OuterClass {
private class InnerClass {
public void innerMethod() {
System.out.println("This is the inner method");
}
}
public void outerMethod() {
InnerClass inner = new InnerClass();
inner.innerMethod();
}
}
public class OuterClass {
public static class InnerClass {
public void innerMethod() {
System.out.println("This is the inner method");
}
}
public void outerMethod() {
InnerClass inner = new OuterClass.InnerClass();
inner.innerMethod();
}
}
public class OuterClass {
private class InnerClass {
public void innerMethod() {
System.out.println("This is the inner method");
}
}
}
public class Main {
public static void main(String[] args) {
OuterClass outer = new OuterClass();
OuterClass.InnerClass inner = outer.new InnerClass();
inner.innerMethod();
}
}
这些方法可以帮助我们在对象方法中引用对象的内部类,并调用内部类的方法。
领取专属 10元无门槛券
手把手带您无忧上云