Here i m declaring an instance of class animal in the same class. In c It is considered an error:
struct demo{
int anyvar;
struct demo anyvar1;
};
因为它应该是无限的宣言。
然后, 为什么在 Java允许使用这一法典?
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();
}
}