answersLogoWhite

0

A class may have both static and non-static methods. Non-static methods are local to objects of the class (instances of the class) and are often known as instance methods for that reason. Being local to an object means they can refer to the current instance of the class through the implicit "this" reference. Static methods, on the other hand, are local to the class and do not have an implicit "this" reference. As such, static methods can be invoked even when no instances of the class are in scope.

Since the main function is the entry point of the application and there can be only one entry point, it doesn't make any sense to declare it an instance member because no objects of the class would physically exist.

User Avatar

Wiki User

10y ago

What else can I help you with?

Continue Learning about Engineering

Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only


What is the use of static in public static void main?

The static keyword signifies that the method belongs to the class and not any of its objects. Hence, the JVM does not have to create an object of that class before beginning execution. Imagine how the JVM would create an object and invokes its method even before the class execution starts. That is why the main method is static and is the starting point of any java application.


Can you overwrite main function in java?

You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.


What is the meaning of java void keyword?

The void keyword is used to show that a method will not return a value. // no return type public void setX(int x) { this.x = x; } // returns an int public int getX() { return x; }


What is static void Main?

The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.

Related Questions

Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only


What is the use of static in public static void main?

The static keyword signifies that the method belongs to the class and not any of its objects. Hence, the JVM does not have to create an object of that class before beginning execution. Imagine how the JVM would create an object and invokes its method even before the class execution starts. That is why the main method is static and is the starting point of any java application.


Why you use main method when you can use static method?

The main method is called by the jvm when your program is executed. The main method is a static method: public static void main(String[] args) {} A static method is method that can be run without instantiate the class (creating an object from it) The main method is a static method. No other static method could replace it's functionality. PS By static method do you mean static initialiser? I often use static initialisers instead of a main method, but in these cases you must still have a main method, albeit an empty one ie. public static void main(String[] args) {} Notice that the method has an empty body A main method must be used if you intend to accept parameters at run time from the jvm.


Can you overwrite main function in java?

You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.


Why the main function is public and static?

The main function is public because it means it needs to be called by any object. I had to check this myself but if you try to make the main function in Java private it will give you a run time error. It is static because it is indicating it is a class method and it does not need to be instantiated. Without the static keyword you would need to do something like this Main main = new Main();


Is it possible to create a static object in main?

Yes, anywhere that you can normally declare an object you can use the static keyword to make that object static.int main (){static Object o;}


what is the difference between final and static keywords?

static: we can use the keyword static either to method or to a variable. when we declare to a method,(eg: public static void main(String args[]),we can use this method without any object. when we use to a variable,there will be only one instance of that variable irrespective of how many objects that get created of that class. Final: Usage of final to method or to a variable makes them as constant. It's value cannot be changed...


Can the main method call the other method if it is not defined as static?

No


What is the meaning of java void keyword?

The void keyword is used to show that a method will not return a value. // no return type public void setX(int x) { this.x = x; } // returns an int public int getX() { return x; }


Void in java?

Void is a keyword in Java. It is always used in method declarations. When used in the line that declares a method, it signifies the fact that the method will not return any value. The JVM will not expect the method to return anything. Ex: public static void main(String[] args) {}


What is static void Main?

The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.


What are the valid signatures of the main method of a class?

The main method can be declared as either of the below: public static void main(String[] args) or public static void main(String args[])