Home » JAVA Programming » Strings » Question
  1. What is the output of this program?

    public class Result
    {
    public static void main(String[]args)
    {
    String[] array = { "for", "tea", "too" };
    String num= (array.length > 2) ? array[2]: null;
    }
    }
    1. The variable num is set to elements[0].
    2. The variable num is set to null
    3. An exception is thrown at run time
    4. Compilation error
    5. None of these
Correct Option: A

The value at the 0th position will be assigned to the variable num.



Your comments will be displayed only after manual approval.