I am not able to understand why this code doesn't compile:
class A {
public static void main(String[] args) {
System.out.println("hi");
}
}
private class B {
int a;
}
I am saving the contents in a file named A.java
- and I get an error:
modifier private not allowed here // where I have defined class B
This happens both when I try B as private and protected. Can someone please explain me the reason behind this?
Thanks !
B needs to be private to something. Place it within the definition of class A or create another file, B.java, and define it there, but then it cannot be private.