instance of a class inside that class in java
<p>Here i'm declaring an instance of class animal in the same class.
In c It is considered an error:</p>

<pre><code>struct demo{
        int anyvar;
        struct demo anyvar1;
};
</code></pre>

<p>because it is supposed to be an infinite loop of declaration.</p>

<p>Then, Why is this code allowed in Java?</p>

<pre><code>class Animal{
    Animal object1 = new Animal();

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

    public void dostuff()
    {
           System.out.println("Compiles");
           object1.dostuff();
    }

    public void keepdoingstuff()
    {
             System.out.println("Doing Stuff...");

             object1.keepdoingstuff();
    }
}
</code></pre>
