Home / Java Programming / Objects and Collections :: Discussion

Discussion :: Objects and Collections

  1. What will be the output of the program?

    public class Test 
    {    
        public static void main (String args[])    
        {        
             String str = NULL;      
             System.out.println(str);    
       }  
    } 

     

  2. A.

    NULL

    B.

    Compile Error

    C.

    Code runs but no output

    D.

    Runtime Exception

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Option B is correct because to set the value of a String variable to null you must use "null" and not "NULL".


Be The First To Comment