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 are recursive functions?

986


What is a double?

1039


What is field name?

948


Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.

986


Define Multiprogramming and Multiprocessing in java.

1063


I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?

953


How do you check if a number is a perfect square?

938


How do you reverse a string in java?

1057


Explain the overview of UDP messaging.

1080


What is an example of character?

1060


What is bubble sort in java?

989


Does the order of public and static declaration matter in main method?

1029


What is the exact difference in between Unicast and Multicast object? Where will it be used?

998


What is difference between module and function?

1083


Why do we use string?

970