I'm newbie in Java, but faced with interesting problem today. My code is provided below.
class Parent {
public void display()
{
System.out.println(new Child().line);
}
private class Child {
private String line = "Greating";
}
}
class Program
{
public static void main(String args[])
{
Parent obj = new Parent();
obj.display();
}
}
It's also available here. Could anyone clarify why private members of nested class is accessible in outer class? I'm a C# developer and was confused having this behavior.