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 a loop java?

1053


Describe method overriding

1126


What is the difference between I ++ and ++ I in java?

982


Are arrays immutable in java?

1085


How do you check if two given string are anagrams?

966


Why you should not use singleton?

982


What is an interface in java? Explain

1193


How do you achieve polymorphism in java?

997


Why we go for collections in java?

981


Is set ordered?

976


What is substring in java?

1224


How do you generate random numbers in java?

1006


How do you replace a string in java?

1004


What is the purpose of methodology?

1080


In case of inheritance what is the execution order of constructor and destructor?

1134