What is the need to declare main() method as static in Java?

Answers were Sorted based on User's Feedback



What is the need to declare main() method as static in Java?..

Answer / juhi

If main method is static it should not be able to access any
other methods(other than static methods). but this is not
the case y?

Is This Answer Correct ?    1 Yes 0 No

What is the need to declare main() method as static in Java?..

Answer / kuldeep vishwakarma

We know very well that when we want to call any method without creating Class object in which that method is reside,this will
be perform by "static" keyword.And in java main()always call by JVM,So we can call main()without instance create with the help of jvm.Therefore we needed static with main();
INTERNALLY MAIN()CALL WITH THE HELP OF TRY-CATCH BLOCK

try{
ClassName.main();
}
catch(Exception e)
{
---------------
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

Define network programming?

0 Answers  


What about 'hostile applets'? : java security

0 Answers  


Which is the best book for whole java study?

12 Answers  


Differences between intermediate operations and terminal operations of java 8’s stream api?

0 Answers  


What is difference between map and flatmap in java 8?

0 Answers  


Why sun introduce concept of anonymous class? What is need and real life use of anonymous class

0 Answers  


What is optional in java 8? What is the use of optional?advantages of java 8 optional?

0 Answers  


In a barber shop there are 2 doors. customer come in 1 door, leave in other. minimum # of chairs. barber spend his life in cutting. always barber can cut 1 customer. few chairs in the shop. if barber busy customer waits, if chairs full, customer leave. if no customer, barber sleeps. treat barber and customer as 2 threads. you can use Semaphore class with arrive and depart and count as parameter.

0 Answers   NCR,


can anyone tell me what kind of questions are asked for core java exam in aptech

0 Answers  


What are the advantages of java sockets?

0 Answers  


Why bean class is used in java?

0 Answers  


What is the use of flatmap in java 8?

0 Answers  


Categories