T
T
The_Pro_Killer2021-06-08 22:32:22
Java
The_Pro_Killer, 2021-06-08 22:32:22

How to pass a variable from a method of one class to a method of another class?

Guys, help! Such a problem: there are 2 classes, conditionally ClassA and ClassB. ClassA has a createName method that has a String name variable. I pass the name to this method. So ClassA looks something like this:
public ClassA {
public void createName(String newName) {
String name = newName;
}
}
In another class (ClassB) in the method, I need to get the name variable, that is, something like this:
public ClassB {
public void wantMyName() {
"And here I need to get my name"
}
}
The example is greatly exaggerated, because in fact I omitted a lot of things, but this is precisely the point of the problem. It seems that I tried to declare a public static String name global variable in ClassA, but either I don’t understand and do something, or it shouldn’t work at all. And, if it's important, the @RequestScoped annotation is hung on ClassA. In general, guys, help! Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-06-08
@The_Pro_Killer

java_dlya_chajnikov_barri_berd.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question