In this example we will show the method to access private inner class in Java.
Source Code
package com.beginner.examples;
class Out {
int a = 10;
private class In { // private inner class
int b = 5;
}
}
public class AccessInnerClass {
public static void main(String[] args) {
Out out = new Out();
Out.In in = out.new In();
System.out.println(in.b + out.a);
}
}
Output:
error: Out.In has private access in Out