Why can outer Java classes access inner class private members?

I observed that Outer classes can access inner classes private instance variables. How is this possible? Here is a sample code demonstrating the same: class ABC{ class XYZ{ private int x=10; } public static void main(String… args){ ABC.XYZ xx = new ABC().new XYZ(); System.out.println(“Hello :: “+xx.x); ///Why is this allowed?? } } Why is this … Read more

Accessing private member variables from prototype-defined functions

Is there any way to make “private” variables (those defined in the constructor), available to prototype-defined methods? TestClass = function(){ var privateField = “hello”; this.nonProtoHello = function(){alert(privateField)}; }; TestClass.prototype.prototypeHello = function(){alert(privateField)}; This works: t.nonProtoHello() But this doesn’t: t.prototypeHello() I’m used to defining my methods inside the constructor, but am moving away from that for a … Read more