So, apparently, in Java, whenever your calling a non-staticmethod/function in a
ID: 3616182 • Letter: S
Question
So, apparently, in Java, whenever your calling a non-staticmethod/function in a class, you must create an object of that classfirst and then call the method from that object. Right now I'mtrying to call one method, method A, in a class fromanother method, method B in the same class. The methodB I'm trying to call will edit the object itself; however,since I don't need to create another object in the methodA I'm trying to call the other method B from, how do Icall the method B I want to call? e.g. public class Object { int NumberToBeChanged = 0; private void ChangeValue(int NewValue) { NumberToBeChanged = NewValue; } public void SetValue() { Object.ChangeValue(3); //this is where the problemis; non-static method cannot be referenced... etc. } } So, apparently, in Java, whenever your calling a non-staticmethod/function in a class, you must create an object of that classfirst and then call the method from that object. Right now I'mtrying to call one method, method A, in a class fromanother method, method B in the same class. The methodB I'm trying to call will edit the object itself; however,since I don't need to create another object in the methodA I'm trying to call the other method B from, how do Icall the method B I want to call? e.g. public class Object { int NumberToBeChanged = 0; private void ChangeValue(int NewValue) { NumberToBeChanged = NewValue; } public void SetValue() { Object.ChangeValue(3); //this is where the problemis; non-static method cannot be referenced... etc. } }Explanation / Answer
If you need any further clarification, just let me know.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.