why we use static in main and String[] args as arugment of main

public static void main (String[] args)

can u explain me following

static member functions should not refer to objects of that class. But we can access static functions through classname itself

7 Years
Discussion Span
Last Post by Mitja Bonca

Ok, The Main method must be static because it needs to exist without first being instantiated.

Static member functions shouldn't use objects in a class that need to be instantiated because they may or may not exist yet when the static function is called.

"but we can access static functions through the classname itself"
I assume would refer to that calling a static function you use the classname to reference the function, where as non static functions you would use the instance name to reference the function.


Here you can find some interesting answers on your question:
and here.
Have a good reading, and take is slow... you have to understand what these keyWords mean. Its something basic for the start.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.