Q. What will be the output of the following Java program?
class Abc
{
public static void main(String[]args)
{
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0]: null;
}
}

  • (A) Compilation error
  • (B) An exception is thrown at run time
  • (C) The variable first is set to null
  • (D) The variable first is set to elements[0]
πŸ’¬ Discuss
βœ… Correct Answer: (D) The variable first is set to elements[0]

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
129
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Pooja
Publisher
πŸ“ˆ
99%
Success Rate