Typically, I write the class definition and then make a separate class to write the definition of the main method to make my class instance and call its methods. However, I have seen that it is possible to have the main method inside the class itself that the main method is calling an instance of. How is that possible? I thought we could not create an instance of a class within the class itself, that just does not make sense.
Here is my example below: How is it possible to have a Test instance within the class definition itself?
import java.util.*;
public class Test{
public int tester()
{
return 5;
}
public static void main(String args[]) {
Test x = new Test();
x.tester();
}
}