Private keyword and virtual function access
<p>I'm learning Java and trying to understand how <code>private</code>, <code>protected</code> and <code>public</code> modifiers affect bindings.</p>

<p>I wrote this code:</p>

<pre><code>public class A {

    public void a() {
        System.out.println("a in A.");
        b();
    }

    private void b() {
        System.out.println("b in A.");
    }


    public static void main(String[] args) {
        B obj = new B();
        obj.a();
    }
} 

class B extends A {
    public void b() {
        System.out.println("b in B.");
    }
}
</code></pre>

<p>The output is:</p>

<pre><code>a in A.
b in A.
</code></pre>

<p>Still, <code>B</code> has it's own <code>b</code> method, and <code>obj</code> is <code>B</code>'s instance. Why the output isn't the following?</p>

<pre><code>a in A.
b in B.
</code></pre>

<p>But if I change <code>b</code> method in <code>A</code> to the following:</p>

<pre><code>public void b() {
    System.out.println("b in A.");
}
</code></pre>

<p>the output changes to the expected:</p>

<pre><code>a in A.
b in B.
</code></pre>

<p>So, why doesn't <code>b</code> behave like virtual function when it's declared with <code>private</code> keyword in <code>A</code>?</p>
