This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Local variables. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Local variables." Watch "Local variables." New topic
Author

Local variables.

Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi can u tell me how to call a local variable.Please explain it with proper examples.

Thank You.
Sainath Veepuri
Ranch Hand

Joined: Sep 25, 2003
Posts: 49
Hi Sameera,

Originally posted by Sameera Abeysinghe:
Hi can u tell me how to call a local variable.Please explain it with proper examples.

Thank You.


====
Any variable which is declared inside a method is called a local variable.
Any variable which is declared inside a class but outside a method is called a member variable.
We can access the local variable, only inside the method of that class.
====
Example:
public class Test {

private int i = 0; // member variable

private void myMethod(){
int i = 1; // local variable
System.out.println("member variable is "+this.i);
System.out.println("local variable is "+i);
}

public static void main(String[] args) {
Test test = new Test();
test.myMethod();
}
}


====
Hope you understood.
- SAi
[ December 01, 2004: Message edited by: Sainath Veepuri ]
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
I think this should help you understand better.


Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
 
jQuery in Action, 2nd edition
 
subject: Local variables.
 
Similar Threads
Are variables defined inside a constructor instance or local?
String operation
Did implicit objects are instance variables or local variables in _jspService
Resource Local Transactions
object/collection modification