Variables:
- Variable is the named location to storing a value.
- It is the name of the memory location
int a=10; // a is a variable
- In java there are three types of variables
1.Local Variable
2.Instance Variable
3.Static Variable
1) Local Variable:
- Variable declared inside the body of the method is called Local Variable.
- we can use this variable only within that method only.
- Local variable cannot be defined with "static" keyword.
public class example { static int a=10; void method() { int b=20;//local variable } public static void main(String args[]) { int c=30; } }
2) Instance Variable:
- A variable declared inside the class but not inside the body of the method, is called Instance Variable.
public class example { static int a=10; void method() { int b=20; } public static void main(String args[]) { int c=30;//instance variable } }
3) Static Variable:
- A variable is declared with static keyword is called static variable
public class example { static int a=10;//static variable void method() { int b=20; } public static void main(String args[]) { int c=30; } }
0 Comments