What will be printed by the following code?

public class Test {
    static Boolean bo1 = new Boolean("true");
    static Boolean bo2 = new Boolean(false);

    public static void main(String[] args) {
        Boolean bo3 = new Boolean(bo1);
        Boolean bo4 = new Boolean("bo2");
The constructor Boolean(String) creates an object with a value of true, if it passed the string "true" (in any register). Otherwise, the object will be created with the value false.
Therefore, the objects will have the following meanings:
bo1 – true
bo2 – false
bo3 – true
bo4 – false
When comparing objects with the same value (bo1 и bo3, bo2 и bo4) the method equals() returns the value true.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback