You need to sign in to do that
Don't have an account?

Variable does not exist. variable - kk and op. how to solve?
public class Calculator2 {
public integer kk = 34;
public integer op = 23;
public integer result;
public static void raj(){
result = kk+kj;
System.debug(result);
}
public integer kk = 34;
public integer op = 23;
public integer result;
public static void raj(){
result = kk+kj;
System.debug(result);
}
Alter your code as below
The issue with your code is that you are trying to access instance variables
kk
andkj
in a static methodraj()
. Instance variables are associated with an instance of the class and cannot be accessed directly in a static method.To resolve the "variable does not exist" error, you need to make the instance variables
kk
andop
also static, or pass them as parameters to the static methodraj()
.If this information helps, please mark the answer as best. Thank you
All Answers
Alter your code as below
The issue with your code is that you are trying to access instance variables
kk
andkj
in a static methodraj()
. Instance variables are associated with an instance of the class and cannot be accessed directly in a static method.To resolve the "variable does not exist" error, you need to make the instance variables
kk
andop
also static, or pass them as parameters to the static methodraj()
.If this information helps, please mark the answer as best. Thank you