-3

Start static variable as true on first mute method to false

I would like the second method to inherit the value of the first and not the global value

calling the public method I want the boolean to receive the value of the private method

public class Test{
    private static Boolean varBool= true;

    private static void fistMethod(){

        varBool= true;

    }  
    public static void secondMethod(){
        varBool;
       //This variable return true value
    }
}
3
  • You are setting a value to true twice. I'm not sure what behavior you are looking for other than getting back true. Could you clarify by an edit, please? N.b. Apex does not have true global variables; this is a static variable.
    – David Reed
    Commented Jul 26, 2019 at 0:01
  • calling the public method I want the boolean to receive the value of the private method
    – Barbilque
    Commented Jul 26, 2019 at 0:24
  • You need an edit here, but it sounds like you're trying to do this in secondMethod Boolean localVarBool = firstMethod(); The problem is your firstMethod is a void return, so it can't get the value from that method.
    – drakored
    Commented Jul 26, 2019 at 0:37

1 Answer 1

1

It sounds like this is what you're attempting to do from the comments. This exposes a public method that grabs the internal variable from a private static method which gets it from the private static variable.

public class Demo {
    private static Boolean varBool= true;

    private static Boolean firstMethod(){
        return varBool;
    }  
    public static void secondMethod(){
        Boolean localVarBool = firstMethod();
    }
}
3
  • 1
    Also, don't name classes Test if you can help it. There is a system class named Test and it will interfere with test classes calling test methods (unless they fixed that weird ability).
    – drakored
    Commented Jul 26, 2019 at 0:56
  • 1
    I tend to prefer Demo as it is very clear what your intentions are.
    – Adrian Larson
    Commented Jul 26, 2019 at 1:00
  • 1
    @AdrianLarson I like that idea. I copy/pasted the original and changed it to not somewhat lazily heh. I've updated with demo.
    – drakored
    Commented Jul 26, 2019 at 1:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .