I am learning how to program and I have a problem with my
public static void main(String[] args) {...
I have a variable that within this procedure changes the value of that variable I need to use it in another class. Example: the variable "c" I need to occupy in another class the same package
public class mishel {
private static int c;
public static void main(String[] args) {
// TODO Auto-generated method stub
int a, b;
a=8;
b=9;
c=a+b;
System.out.println(c);
}
public void set_c(int var1){
this.c=var1;
}
public int getc(){
return this.c;
}
}
/////////////////////////////////////////////// //////////
In my other class I have
public class programa {
public static void main(String[] args) {
// TODO Auto-generated method stub
mishel c1=new mishel();
c1.getc();
int nc=c1.getc();
int d = nc;
System.out.println(d);
}
}
But it prints me 0
.