answersLogoWhite

0


Best Answer

The static modifier means that it does not have to be instantiated to use it. Before a program runs there are technically no objects created yet, so the main method, which is the entry point for the application must be labeled static to tell the JVM that the method can be used without having first to create an instance of that class. Otherwise, it is the "Which came first, the chicken or the egg?" phenomenon. Your main method should be declared as follows: public static void main (String[] args) { lots of your java code... } As we know, java is a pure OOP , that means everything should be in the class, main. Aso, because main is itself a function, static member functions should not refer to objects of that class. But we can access static functions through classname itself, as: class TestMain { public static void main(String args[]) { body; } } Now, cmd>javac TestMain.java cmd>java TestMain as we know the static member functions has to call through its class name. That's why the programme name must be same as the class name ,where we wrote the main function. Another important point is : static variables or member functions will load during class. That means before creating any instances(objects), the main function is the first runnable function of any program which we run manually, such as : cmd>java TestMain(run) if , any sharing information.

User Avatar

Wiki User

โˆ™ 2009-04-10 19:44:01
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar

Add your answer:

Earn +20 pts
Q: Why should main be declared static and is declaring it public and void not sufficient?
Write your answer...
Submit
Related questions

Do think that US was justified in declaring war on Germany?

At the start of the US involvement in WW II, the US was attacked by the Japanese. When the US declared that a state of war existed between the US and Japan, Germany declared war on the US. Your question should be was Germany justified in declaring war on the US.


Should an instance field be declared as public or private?

ask mrs. jain


Why user defined applet class declared public?

Applet class should be declared public so that it can be accessed outside when it is run on browser or thro' appletviewer tool. -Shini Saji


What is fiscal adequacy?

this means that the source of revenue should be sufficient to address the demands of public expenditures.


a major newspaper runs an editorial declaring that the U.S. Senate should confirm a new Supreme Court Justice. What method of shaping public opinion does this represent?

Direct argument


What are the Example of fiscal adequacy?

the source of revenue should be sufficient to meet the demands of public expenditure.. ---15---


What are the examples of Fiscal adequacy?

the source of revenue should be sufficient to meet the demands of public expenditure.. ---15---


The us should have waited to be attacked before declaring war during world war 2?

The US was attacked before declaring war in WW2, by the Japanese at Pearl Harbor. Does it make it right what Hitler was doing in Europe because the US declared war on them rather than vice versa ? Of course not.


Member modifier 'public' must precede member type and name means in computer C language?

While you declaring the global variable you should declare it correctly... This problem mostly arise because any one of the data type in global should not have variable.


When you implement an interface method it should be declared as public in java?

This is not necessarily true. The only rules for this are that interface methods may not be private. They may be public, protected, or have the default (blank) access modifier.


What is a sentence with the term self-sufficient?

you should always be self sufficient and not depend on others only


Who declared war first during Spanish American war?

As a result of the 4 resolutions from congress (asked by McKinley), Spain declared war on the U.S the three resolutions included declaring that Cuba should be independent, demanding Spain to back off Cuba, allowing the president to use force to get rid of the Spanish, the last didn't amount to war but settled the issue if Cuba should be annexed.


Can you give me a sentence with the word sufficient?

The content of this sentence should be sufficient to satisfy your needs.


Is the centre declared for ssc board exam 2013?

Yes, the centers are declared. The list should be declared at the school.


Who declared that Pluto should not be a planet?

The International Astronomical Union declared in 2006 that Pluto should be reclassified as a dwarf planet.


Should or shouldn't students have homework during holiday breaks?

Yes, they should have sufficient homework. The exact quantity comprising "sufficient" is, potentially, debatable.


How long should you wait in declaring bankruptcy after removing your name from a property deed?

It should be more than 30 days


What bit should you use for a strong horse?

A bit such as a kimberwhick or hackmore should be sufficient.


What type of gas should be used for a 1986 cutlass?

87 octane should be sufficient


Did the Americans do everything they should have before they declared independence?

no they did not


What food should you have with wine?

This question lacks sufficient detail to answer...


Why should we employ you as care assistant?

Because I am self sufficient.


Can you return a reference to public data member?

Yes, but since it is public there is no need to; any code outwith the class can access a public data member directly. If it were a private data member, then returning by reference would defeat the point of making it a private data member in the first place; you might as well make it public. Private data members should always be returned by value, never by reference and never by pointer, and data members should only be declared public if they are not critical to the internal operation of the class.


Where is ssc exam center no2292?

The center name should be declared by the school . They are generally declared before the practicals begin.


Which emperor willed on his life that the Roman empire should be split into two parts?

No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.No emperor declared that the empire should be split into two parts. It was historians that made the distinction in order to avoid confusion.