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

Answer Posted / anil chahal

We write main method as static because we call this method
from class name. We are not instancing by making its object
so if we call from class name we must have to write static .
we write void because main method is return nothing.Public
because there is always only one main class that is one file
having only one main file, because this main file may be
used anywhere means
outside this package so public keyword is must.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we achieve thread safety in java?

689


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

681


What is the function of compareto in java?

592


What is an example of a boolean?

571


Are private methods final?

488






Does importing a package imports its sub-packages as well in java?

554


Detail discussions on JVM, memory management and garbage collector.

556


Describe the Big-O Notation.

618


What is the difference between integer parseint and integer valueof?

551


What is a boolean in java?

579


Differentiate between the constructors and methods in java?

511


How would overload a function based on return type?

552


What is data type modifier?

529


What is main in java?

515


What differences exist between iterator and listiterator?

573