I have two java files in same package. I want to take the updated value of one variable from one file to another. I wrote the following code. In class1.java :-
import javax.swing.JOptionPane;
public class class1 {
public static String bar = "Yes";
static int age = 26;
public static void main(String[] args){
switch(age) {
case 25: bar = "world";
break;
case 26: bar = "good";
break;
case 27: bar = "very";
break;
case 30: bar = "hello";
break;
default: JOptionPane.showMessageDialog(null,"Please");
break;
}
}
}
In class2.java :-
public class class2 {
public static void main(String[] args){
class1 second = new class1();
System.out.println(second.bar);
}
}
The problem is that the final value is printed Yes which should not be printed. The output should be good. Please help me.