Programming Language String in Java Question #2228
Single Choice Not Set

QDetermine 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");
            }
      }
}

ID: #2228 String in Java 1,541 views
Question Info
#2228Q ID
Not SetDifficulty
String in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Compilation fails.
  • B "1" is printed.
  • C "2" is printed.
  • D An exception is thrown at runtime.
Correct Answer

Explanation

An exception is thrown at runtime.

Share This Question

Challenge a friend or share with your study group.