JAVA VARIABLES
JAVA VARIABLES |
Variables is a name of memory location There are three types of variables in java
- Local variable
- Instance Variable
- Static Variable
|
A local variable cannot be defined with "static" keyword.
package variables; public class localvariable { public static void main (String arge[]) { int a = 10; //local variable System.Out.Println(a); } } |
OUTPUT: 10 |
package variables; public class instacevariable { int a = 10; //Instace variable public static void main (String arge[]) { instacevariable iv = new instacevariable(); System.Out.Println(iv.a); } } |
OUTPUT: 10 |
A variable which is declared as static is called static variable it cannot be local.
package variables; public class staticvariable { Static int a = 10; //static variable public static void main (String arge[]) { System.Out.Println(iv.a); } } |
OUTPUT: 10 |