Ejemplo 1: ejecutar una clase java sin el método principal
//This is prior to Java 7
class StaticInitializationBlock{
static{
System.out.println("class without a main method");
System.exit(0);
}
}
Ejemplo 2: ¿Podemos ejecutar un programa sin el método main ()?
Yes, one of the ways to execute the program without the main method is
using static block
What if the static modifier is removed from the signature of the main method??
Program compiles. However, at runtime, It throws an error "NoSuchMethodError
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)