A Stackoverflow error will occur whenever you try to create an instance of the same class as a member variable. Thus, the h instance is created endlessly, and therefore a stackoverflow error has occurred.
For example, the code you specified, even without an inner class, will throw a stackoverflow error
public class maininherit { maininherit h=new maininherit(); public static void main(String[] args){ maininherit t=new maininherit(); t.mai(); } public void mai(){ System.out.print("hellllll"); h.mai(); }}
Avoid creating an object of the class itself as a member or field
source share