answersLogoWhite

0


Best Answer

No

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Does the order of public and static declaration matter in main method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How many types can write public static void main in java?

You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


Is there any change by interchanging the position of main in Public static void main in java?

No. You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


What if you write static public void instead of public static void?

It would actually make no difference. The presence of the keywords during the declaration of the main method is important and not the order. so a static public void main(String[] args) would just compile and run perfectly fine just like public static void main(String[] args)


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


When will you define a method as static in java?

Static keyword when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class) Ex: public class StaticTest { public static String getAuthorName() { return "Anand"; } } Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as: String authorName = StaticTest.getAuthorName();

Related questions

How many types can write public static void main in java?

You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


Is there any change by interchanging the position of main in Public static void main in java?

No. You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


What if you write static public void instead of public static void?

It would actually make no difference. The presence of the keywords during the declaration of the main method is important and not the order. so a static public void main(String[] args) would just compile and run perfectly fine just like public static void main(String[] args)


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


How do you code and call a static method?

class MyClass { // Declare a static method to return the square of a number. public static int getSquare(final int n) { return n*n; } public static void main(String[] args) { // Call the static method to find 1522 System.out.println( MyClass.getSquare(152) ); } }


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.


What is the difference between public static void and static void?

The "public" prefix makes the method available from outside the class.The "public" prefix makes the method available from outside the class.The "public" prefix makes the method available from outside the class.The "public" prefix makes the method available from outside the class.


When will you define a method as static in java?

Static keyword when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class) Ex: public class StaticTest { public static String getAuthorName() { return "Anand"; } } Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as: String authorName = StaticTest.getAuthorName();


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[])


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 translation method allow a server to always keep the same public address?

Static NAT Static NAT with Overload


How do you invoke static methods?

if some method is static, then you can not call that method through the oobject of that class. but the name of the class. let us see a example: class Test { int a; int b; static void show() { System.out.println("we are in show"); } } class Main { public static void main(String args[]) { Test t=new Test(); t.show();\\thiss is an erroraneous code. because, the method "show()" is static. Test.show();\\this is correct } Arnas Sinha