answersLogoWhite

0

Short answer: No.

Only class member variables may be declared static. Local variables with a static declaration will throw an error (usually "illegal start of expression").

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

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


How do you write a program in c plus plus in which static variables are declared?

#include <stdio.h> static int myvar1, myvar2; int main (void) { puts ("It was easy"); return 0; }


Is it possible to write an algebraic expression with two variables and no operations?

Yes, an algebraic expression needs no operation and can have multiple variables.


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 it compulsory to write static with void main?

Every C# application is started on the startup class' static Main method. Yes, it must be static, but void is not the only returned type. The 4 signatures:static void Main();static void Main(string[] arguments);static int Main();static int Main(string[] arguments);Ideally, there should be one and only one Main method in your application.


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 method should be used In cases where it is not possible to reasonably estimate uncollectibles?

Direct Write-off


Define method overloading and write two method headers that together exhibit overloading?

Method overloading is when two or more methods have the same name, but the computer can differentiate between the methods by looking at the parameters. Example: public static void go(int x) public static void go(double x) If you pass an int, the first method would be called. If you pass a double, the second method would be called


Is it possible to overload the main methode in java?

Yes. The main method can be overloaded just like any other method in Java. The usual declaration for main is: public static void main(String[] args) throws Exception; When you launch a java application it looks for a static method with the name 'main', return type 'void' and a single argument of an array of Strings. ie what you throw is unimportant in resolving this method. Overloading is providing multiple methods with the same name but different arguments (and potentially return type). The following class is valid: public class Test { public static void main(Object[] o) { } public static boolean main(String[] o) { } } But when run will result in the error: Exception in thread "main" java.lang.NoSuchMethodError: main Since the methods present does not have the correct signature.(The main method with the void return type is missing. Without it the code cannot be executed by the JVM) Overloading is sometimes confused with overriding. Overriding is changing the behavior of a method in a subclass. This is not allowed on a main method because main must be static and is therefore bound at compile time, not run time, e.g., the program: class A { static String foo() { return "A"; } } class B extends A { static String foo() { return "B"; } } public class Test { public static void main(String[] args) { A a = new B(); System.out.println(a.foo()); System.out.println(((B)a).foo()); } } Prints: A B This is why it is generally discouraged from calling static methods on instance variables. You should always write A.foo() or B.foo() as this reminds you that there is no polymorphic behavior occurring.


Advantages of static keyword in java?

When we want that a class member should be used independently of any object of that class, we have to precede that member's declaration with the keyword static .When a member is declared as static, it can be acccessed without creationg an object of the class and without referring to the object.That static is , a static member belons to a class as a whole and not to any one instance/object of that class.The static member is shared by all objects of thatclass.


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)


How do you write java program using two main method?

When you start your xxxx.class it will execute its 'public static void main (String args[])' method. Any other main methods won't be executed, only if your program explicitly calls them.