Junior — Middle
Does the inner class have access to the members of the outer class?
sobes.tech AI
Answer from AI
Yes, an inner (nested) class in Java has access to all members of the outer class, including private fields and methods. This is because the inner class is part of the outer class and can directly access its state.
Example:
public class Outer {
private int value = 10;
class Inner {
void printValue() {
System.out.println("Value: " + value); // access to private field of the outer class
}
}
}