What is the result?

public class Test -[
public static void main(String[] args) {
boolean a = new Boolean(Boolean.valueOf (args[0])); boolean b = new Boolean(args[1]);
System.out.println(a + " " + b);
And given the commands:
javac Test.java
java Test TRUE null
What is the result?
A. TRUE null
B. true false
C. false false
D. true true
E. ACIassCastExceptionisthrown at runtime.

Download Printable PDF. VALID exam to help you PASS.

6 thoughts on “What is the result?

  1. Answer B:

    One of the constructors of Boolean wrapper classes takes a String argument (i.e. Boolean(String s) ). This constructor allocates a Boolean object representing the value “true” ONLY in case the supplied string is equal to “true”, ignoring the case (i.e. capitals or small, or mix). Otherwise, it represents the value “false” if the String is null or anything else.

    The (Boolean.valueOf() ) method takes either a String or a boolean value. For the String parameter, same rule applies. For boolean parameter, it is clear 🙂 .

    The args[0] is actually a “true”, meaning that the constructor will be Boolean(true), and this gives the boolean “a” variable the value of “true”.
    The args[1] is null, giving the boolean “b” the value of “false”.

  2. Answer is B

    public class Test {
    public static void main (String[] args){
    boolean a = new Boolean(Boolean.valueOf(“TRUE”));
    boolean b = new Boolean(null);
    System.out.println(a + ” ” + b);

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.