variable.java
1 public class variable { 2 //Error inducing option 3 char c; 4 5 //Solution no 1 6 static char d; //Allocates memry during compile time 7 8 public static void main(String[] args) { 9 int a = 10; 10 //c = 'W'; 11 //System.out.println(c); // This will giev error as c has no allocated memory or is not an object 12 13 d = 'Q'; 14 System.out.println("d value as a static variable: " + d); 15 16 //Solution number 2 17 18 variable data = new variable(); 19 20 data.c = 'W'; 21 22 System.out.println("c value as an object: " + data.c); 23 24 } 25 }