Can a class instantiate itself?

java, oop

Solution

It's not uncommon for a `main` method to create a new instance of the class it's defined in. But creating an instance won't call `main` again. Remember, `main` is a static method, not tied to any particular instance.

Problem

I was looking at example code on a website. Here is a snippet, ``` public class ManageEmployee { private static SessionFactory factory; public static void main(String[] args) { try{ factory = new Configuration().configure().buildSessionFactory(); }catch (Throwable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } ManageEmployee ME = new ManageEmployee(); /* Add few employee records in database */ Integer empID1 = ME.addEmployee("Zara", "Ali", 1000); Integer empID2 = ME.addEmployee("Daisy", "Das", 5000); Integer empID3 = ME.addEmployee("John", "Paul", 10000); ``` Why is this class calling itself? Looks like it would just keep calling itself in a loop. What is this class doing here, `ManageEmployee ME = new ManageEmployee();`? Thanks.

Original source