How to use return values from methods?

I’m a little bit confused when it comes to using return values from one method in one class in another class. I will write how I think it should be done and if it is correct please let me know, if it is not correct please tell me how it should be done.

public class ClassA {

public typeofparameter nameofvariable; //creating a global variable in classA.

public void MethodA() {
    nameofvariable = something of type typeofparameter;
public typeofparameter MethodB() {
    return nameofvariable;


public class classB {

public typeofparameter nameofvariable; //May nameofvariable in ClassB be used as if it was created and initialized in ClassB while coming from ClassA using this way of doing it and can this be done for any number of classes doing eksactly the same?
public ClassA classa;

public void methodC() {
    nameofvariable = classa.MethodB();


public typeofparameter nameofvariable;

Is not global variable, its a local variable, if it would be tagged as static, then it would be.

Otherwise everything looks correct