In which class public static void main(String ar[]) is declard in java

Showing Answers 1 - 29 of 29 Answers

ramu

  • Oct 12th, 2006
 

public can acceable to any where ,static is at  the time of gining startic memory will be alocated,void can return nothing,main is the Excution of the program(in ths one any element can take string type only)

  Was this answer useful?  Yes

aarthi

  • Oct 15th, 2006
 

this should be declared only for the main class which gets executed

  Was this answer useful?  Yes

G.sandeepreddy

  • Oct 17th, 2006
 

in main class we should write the public static void main(string args[ ]).these are the library functions and the program execution starts from main.

  Was this answer useful?  Yes

Abhishek

  • Oct 18th, 2006
 

Hi Friends,

  Generally we write the main method in main class but there is no restriction for declaring it, It's mandatory for main class but if you have inner classes then you can declare it in those also because compiler checkes only in the class which is being compile.

                                                              Abhishek(Sharad)

  Was this answer useful?  Yes

chitteti

  • Oct 21st, 2006
 

Hi,

Whichever class we saved the .java file, in that class we must declare the main() method as static, because The JVM will call that main() method using the class name.main(String args[]) method internally without creating an object. This is the starting point of the program.

Thanks,

Chitteti.

  Was this answer useful?  Yes

Rohit

  • Nov 8th, 2006
 

in Object class

  Was this answer useful?  Yes

Mani

  • Nov 9th, 2006
 

Actually, for main class we willl not be creating any instance, so to excute it self only we give static, main should be accessible to everywhere by the way we give public for it.

The argument values takes the promted values as string format, by default

jave converts all the incoming value to string, using toString[] method.

  Was this answer useful?  Yes

chinnu

  • Nov 18th, 2006
 

hi,we can write the main method according to the where to start the our program.actually we run the any program it checks the main thread.main thread is daemoen thread .bye chinnu

  Was this answer useful?  Yes

Mahendra

  • Feb 24th, 2007
 

this main method should be declared in a class where the name of the java file matches with that particular class name.

Suppose, we have 2 classes in the below program and we need to write main method in the second class as we are giving the file name as example.java

example.java

public class sample{
public String var1="mahi";
}
public class example {
public static void main(String ar[])
{
sample obj=new sample();
System.out.println(obj.var1);
}
}

  Was this answer useful?  Yes

public : its access specifier, can acces any where

static: this allows main() method with out creating the object and without refer to any instance of the class

void:  does not return a value

main:  this method allows actual applicatin begins and compiler starts the excution from main() on wards.

args[] : recieves command line arguments at run time

  Was this answer useful?  Yes

dvs198528

  • Jun 6th, 2008
 

public static void main(String ar[]) is in the class whose name is same as the name of the program name.

Reason : To start the execution of the program initiating from main().

  Was this answer useful?  Yes

sat.beit

  • Jun 6th, 2008
 

Main method define in class from which excution of the application will get start.
Which u can called main class of the file and file name will be the same as main
class.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions