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 / shreya

main method is the starting point of our program
execution.and it calls first outside the program so that we
have to specified it public.public means access from
anywhere.
Java is strictly object orinted programming language and we
can access any method by using the object.but this is first
method rite now we don't have any object so that static
keyword is used.We can use static method without having the
instance of this class.
void means this function doesn't return anything.
String args[] specified the string array it is use to take
compile time arguments.It takes only String type argument.
There is one question arise if we don't want to pass the
argument although why we use String args[].Answer is
runtime calls always method with String argument but you
can overload main method....

public class Simple
{
public static void main()
{
System.out.println("My Main");
}
public static void main(String args[])
{
Simple.main();
}
}

when you run this program your runtime calls main method
with string arguments first.and then call main method
without arguments and the output will be "My Main".

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of 'super' keyword inside a constructor?

958


what is the use of bean managed and container managed with example?

1965


What is java reflection?

967


What are the procedures?

1053


What is the benefit of singleton pattern?

979


This abstract class is correct ? abstract class A { public abstract void Disp(); public abstract void B() { } public absract virtual C() { } }

982


How to run a JAR file through command prompt?

1260


What is mnemonic code?

1008


When will you define a method as static?

1085


Why does my function print none?

944


What is an example of a conditional statement?

1033


Where can I find jdk in my computer?

961


Why is multiple inheritance not supported in java?

1018


Why char array is favored over string for the storage of passwords?

1064


Why is the singleton pattern considered to be an anti pattern?

879