• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local variables.

 
Sameera Abeysinghe
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can u tell me how to call a local variable.Please explain it with proper examples.

Thank You.
 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this should help you understand better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic