package javaapplication6;
class abc{
abc obj1=new abc();
public void method1(){
System.out.println("Hellworld");
}
}
public class sample3{
public static void main(String arr[]){
}
}
I am trying to create an object of the class abc( ) in the class itself, I am assuming there are no syntactical errors in this code, however what exactly is happening here if I do this ?
ChatGPT Says :
" When you declare abc obj1 = new abc(); directly as an instance variable of the abc class, it creates an infinite loop of object creation. This is because every time you create an instance of abc, it tries to create another instance, and this process repeats indefinitely. "
what does this mean? can someone please explain me the whole process step by step of what's happening in this code, please?