aspose file tools*
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
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"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Local variables.