Can we execute program without main method
Answer: Without main method you can not run java class as an application because at runtime java will search main method and don’t find it it will throw exception. Please see example class below:
package com.javahonk; public class MainMethodTest { static { System.out.println("Static block"); } }
You could compile above class but if you try run it from command prompt you will see below exception: