How to pass variable from class to class?

I need to transfer a variable from main class to another class. There to process it and return the result back. Wrote that you need to pass the variables by creating objects, but thus something I couldn't do it. Intelligent search engines I no longer given.
July 8th 19 at 15:41
2 answers
July 8th 19 at 15:43
Create getters and setters.
July 8th 19 at 15:45
public class A {
 private int privateA;
 public int publicA;

 public int getPrivateA() {
 return privateA;
}

 public void setPrivateA(int privateA) {
 this.privateA = privateA;
}
}


public class Main {

 public static void main(String[] args) {
 A A = new A();
a.setPrivateA(777);
 a.publicA = 888;
System.out.println(a.getPrivateA());
System.out.println(a.publicA);
 int temp_value = a.getPrivateA();
 temp_value = temp_value * 25;
a.setPrivateA(temp_value);
System.out.println(a.getPrivateA());
}
}


Conclusion:
777
888
19425


It is preferable to work with variables how variable privateA, not publicA .

Find more questions by tags Java