Wednesday 30 January 2013

Can we execute without main () method Program in java

// * execute without main method Program *//

class Maind
{
static
{
System.out.println("Hello execute without main method.");
System.exit(0);
}
}

Compile :     javac Maind.java
       Run :    java Maind
Output :-
               Hello execute without main method.
______________________________________________


// *....... execute without main method Program........... /


class Maind
{
static
{
System.out.println("Hello execute without main method.");
}
}

Compile : javac Maind.java
Run: java Maind

Output :-
               Hello execute without main method.
               Exception in thread "main" java.lang.NoSuchMethodError: main

No comments:

Post a Comment

What is Map Collection?

A map collection refers to a set of maps that are compiled and organized for a specific purpose, such as research, education, or preservatio...