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.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback