I am having this code in which I have created an object of class namely MyClass in it. I have created an object inside main method. I want to call the method of class but it gives StackovetrflowError at run time.
Suggest me the way to overcome the error.
here is the code...
class MyClass {
public MyClass obj2 =new MyClass();
public void show()
{
System.out.println("in show method...");
}
void message()
{
System.out.println("in message method...");
}
}
public class AccessDemo {
public static void main(String[] args) {
MyClass obj1 = new MyClass();
obj1.obj2.show();
}
}
I want to get the message printed inside the methods namely show() and message().