Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

could you run the java program without main method?

Answer Posted / amit singh

yes you can run java peogram without main
we do it through the static block ,because its execute
before the main method,
so when the class is loaded it will execute before main
but whrn the static block excute and after exiting it jvm
search for main when it will not fou8nd it then it throw
some exception so for this we use the
System.exit();
class Moon
{
static
{
System.out.println("hello i am visible without main");
}
System.exit();
}
Thanks amit singh

amitsing2008@gmail.com

Is This Answer Correct ?    36 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is java used for?

979


Can a class have multiple superclasses?

1091


how its run?

1015


What is tcp ip in java?

1068


Can we override tostring method in java?

934


What is sizeof () operator?

933


Why is singleton instance static?

958


What is finally and finalize in java?

1022


What is the purpose of garbage collection in java? When is it used?

1005


what are the methods in object?

1099


what is the swingutilities.invokelater(runnable) method for? : Java thread

995


Explain aggregation in java?

931


What is the difference between an array and an array list?

969


Can I learn java in 3 months?

964


What is an anonymous class in java?

1023