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");
        System.out.println(bo1.equals(bo3));
        System.out.println(bo2.equals(bo4));
    }
}
Explanation
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 and bo3, bo2 and bo4) the method equals() returns the value true.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты