You need to sign in to do that
Don't have an account?
sai sai 56
Static method cannot be referenced from a non static context: void Static_vs_NonStatic.staticMethod()
public class IS_stVSnst {
public integer z= 7;
public integer x= 9;
public static integer a= 9;
public static integer b = 7,result;
public void kyun(){
result = z+x;
system.debug(result);
}
public static void how(){
result = a+b;
system.debug(result);
}
}
public integer z= 7;
public integer x= 9;
public static integer a= 9;
public static integer b = 7,result;
public void kyun(){
result = z+x;
system.debug(result);
}
public static void how(){
result = a+b;
system.debug(result);
}
}
The code does not have any issue. Can you confirm when you are facing the error. Is it calling this method from anonomous window?
Thanks,
If you are doing something like below, You will see the error come up :
Try doing this instead :
As you have declared the method how() as static, you cannot invoke the method in a non-static context.
You can only invoke in a static context, which is this : IS_stVSnst.how();