What will be the result of the following code compilation and execution?

public class Main {
    public static void main(String [] str) {
        Boolean value = new Boolean("true");        
        System.out.println(value);
        value = new Boolean("tRuE");                        
        System.out.println(value);
        value = new Boolean("test");                           
        System.out.println(value);
        value = new Boolean(true);                            
        System.out.println(value);
        value = true;                                                 
        System.out.println(value);        
    }    
}
Explanation
If a constructor with string parameter is used during the creation of an object of the Boolean class, then the object will contain the true value and only if the string-parameter coincides with the "true" (case insensitive). I.e. Boolean("true") and Boolean("tRuE") will result in true, but Boolean("test") - in false.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes