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

Recommended Answers

All 2 Replies

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.

Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.