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...

In Java why we write public static void main(String args[])
why not main()?

Answer Posted / sanjay gupta

public static void main()

1> Main() is the entry point of the program. Rather we can
say it is the main gate to enter inside the apartment. It
should be public because the compiler need to enter inside
the method (The guest need to access the apartment to reach
the security guard).

Public--> Compile whos is from another instance need to
access this method.

Statis --> Since main method is written inside a class and
to access a method of a class we need to create an object
of that class first. Since main() is the method which
compiler nned to call before creating any object of that
class we need to declare main as static. Static methods can
be called directely by using the class name. Thats why the
neame of the file should be same as the name of the class
contain main() method.

Void--> Since the method can return any type of valu or it
might not return anything also so the comiler is designed
in such a way that it should not take any return value so
we declare main as void type.

For further information please reach me at
sanjaygupt1011@gmail.com

Thanks~
Happy Programming...

Is This Answer Correct ?    88 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is java util collection?

1019


Is string is a data type in java?

995


What is a finally block?

935


List primitive java types?

989


What is string in java? String is a data type?

966


Why are functions called methods in java?

958


Why is stringbuffer called mutable?

946


What is the difference between static method and instance method in Java?

1149


Why do we use variables?

938


Where is java located?

993


How can we create a thread in java?

979


worst case complexities of Quick sort and Merge sort.

961


Explain about OOPS concepts and fundamentals.

1011


What are the advantages of functions?

878


Can we serialize static variables in java?

1056