What is the mechanism behind object class in java?
<pre><code>class A{}
class Z{}
class S{}

public class Demo6 {

    void fun(A a){
        System.out.println("A reference");
    }

    void fun(Z z){
        System.out.println("Z reference");
    }

    void fun(Object o){
        System.out.println("other reference");
    }

    public static void main(String args[]){
        new Demo6().fun(new A());
        new Demo6().fun(new S());
    }   
}
</code></pre>

<p>Output of the above code is coming:</p>

<p>A reference</p>

<p>other reference</p>

<p>My confusion is how "other reference" is printing when we are passing 'S' class object. Elaborate the actual mechanism of how 'S' class object is compatible with the "Object" class.</p>
