answersLogoWhite

0

The same identifier (variable name) may be used for at most one variable in each scope. Each method has its own scope, in addition to the global scope which is accessible from all others. However, each scope would have a different variable than every other scope despite using the same name for it.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How you can declare local variable?

variable exit within a function and curly braces is local variable int main() { int x; }


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...


Where the variables are stored in the computer?

Variable stored in the memory block inside the RAM. whenever we declare a variable it would take space in main memory and consume it's size from RAM.


Can you write multiple Mains in C-Sharp programming?

No. There can only be one main method, however you can declare new methods, and call them from the main method. Or you can use multi-threading, to simulate having multiple main methods.


How do you call global variable value in main method if main method contains same variable holds another value?

we can call global variables in main method by using scope resolution operator(::) if local and global have same name for example int x=10; main() { int x=20; cout<<x; //x=20 cout<<::x; //x=10 }


Is it possible to call static methods with out creating object?

Yes, we can access all methods which declare with static means then we can access.. ex: class s{ static method() { System.out.println("Welcome"); } } class fun{ public static void main(String args[]) { method(); } }


Why do you write void to the first of main?

Because main is the first method being executed, the Java Virtual Machine cannot expect any return values from this method. Since void is the term used to refer to a variable that does not return any value, we use the key word void for the method signature of the main method


In c plus plus are local declarations visible to the function in a program?

If you declare a variable inside of any fuction (except main) it will not be available to other functions.


Is it possible to define a java static method inside a main method?

Because, the main method is the starting point of the java program and if we need an object of that class even before the main can be invoked, it is not possible. Hence it is declared static so that the JVM Can acess the main method without having to instantiate that particular class


Why java program is not running without the IOException declaration in main method?

Most likely, one of the methods you're calling is throwing an IOException. You either need to declare it to be thrown in the main method or surround the statement with a try-catch block.


Is it possible to declare a variable in a method and use it in a main?

Yes you can and they are known as inner methods. You can even delcare an inner class and methods on it. However, if you want your classess accessible from multiple programs (reusability), then you should not use this practice. This type of facility is useful when you know for sure that your class or method is going to be used only once.


Can you declare main as final or not and why?

Yes you can. Try this: public class TestMain { /** * @param args */ public static final void main(String[] args) { System.out.println("Inside final mail method..."); } } It will print "Inside final mail method..." in the console.