Q. Determine output:
public class Test{
public static void main(String args[]){
String str = null;
if(str.length() == 0){
System.out.print("1");
}
else if(str == null){
System.out.print("2");
}
else{
System.out.print("3");
}
}
}

  • (A) Compilation fails.
  • (B) "1" is printed.
  • (C) "2" is printed.
  • (D) An exception is thrown at runtime.
πŸ’¬ Discuss
βœ… Correct Answer: (D) An exception is thrown at runtime.

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
143
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Ritu Singhal
Publisher
πŸ“ˆ
97%
Success Rate