Why is the access to a private field not forbidden?
<p>For my study in the university I'm forced to do some ugly java basics, like working without encapsulation, main method in the same class etc. (I do not want to open a discussion on a java styleguide, I just want to clarify, that I would not write something like this outside of the university)</p>

<p>I've stumbled across a behaviour that I can't explain to my self:</p>

<pre><code>public class Person {
  // fields
  private int age;

  public static void main(String[] args) {
    Person foo1 = new Person();
    foo1.age = 40;
    System.out.println(foo1.age);
  }
}
</code></pre>

<p>Why does this piece of code compile and run without error? How is it possible that I can access the private field? Strange behaviour due to having the main Method in the same class?</p>
