google search

Thursday, January 26, 2012

CREATE A JAVA PROGRAM WITHOUT MAIN METHOD

class Cool
{
static
{
System.out.println("This java program have run without the run method");
System.exit(0);

}
}


AS THE MAIN BLOCK EXECUTES THE STATIC BLOCK FIRST, IT ENCOUNTERS STATIC BLOCK AND EXECUTES THE STATEMENTS PRESENT. BUT IT THROWS A EXCEPTION AS THERE IS NO MAIN METHOD. TO ERADICATE THIS WE USE SYSTEM.EXIT(0) STATEMENT TO EXIT FROM THE PROGRAM FORCIBLY.

0 comments:

  © Blogger templates ProBlogger Template by Ourblogtemplates.com 2008

Back to TOP