+ 3

How can i use non static variables in class methods??

when i use them, my code didn't run and message non-static variable cannot be referenced from a static context what can i do to solve this problem and don't use static variable??

25th Mar 2019, 5:58 PM
Zahra Shz
Zahra Shz - avatar
3 ответов
+ 15
You have to firstly create an instance of that class, then only you can call non-static methods, like this: MyClass itsInstance = new MyClass(); // Created instance of class itsInstance.yourNonStaticMethod(); // Non Static method called
25th Mar 2019, 6:04 PM
Letsintegreat
Letsintegreat - avatar
26th Mar 2019, 12:38 AM
Denise Roßberg
Denise Roßberg - avatar
0
Yo can use get() and set() methods,too
27th Mar 2019, 11:50 PM
Jaime Andres
Jaime Andres - avatar