Monday, January 17, 2011

Method Local Variables

Method local variables are declared between the opening  and closing braces of a method. These variables are only visible to the methods in which they are declared. 






Method Local variables are not accessible from the rest of the class.
As a example if you declared a variable called m in the main method you cannot access  that variable from another method.




This gives you a compile error . It tells you that it cannot find variable  m.

Important 

Method local variables don't have any default values.
That means if you re using a method local variable without been initialized compiler gives you a compile error.


But when not using that method local variable , compiler does not gives you any syntax error.



-Tharindu Dilshan-



No comments:

Post a Comment