I have this basic question, how is the following code able to access the instance variable even though its private? (the code compiles without any errors)
Please refer to line 10 of the code above,
So specifically, the question i have is: "is static main() method allowed to access private instance variable of the class just like any other instance method?". This is confusing me a bit.
Private doesn't mean private to the instance; it means private to the top-level class. I specifically said top-level class, because private members of nested classes can be accessed by the enclosing class as well.
In line 10 of your code you are trying to access a private variable via instantiating an object of the same class. Though it is a private variable it is accessible anywhere in class it is defined. It is hidden from external classes but available within the same class.