Home / Java Programming / Objects and Collections :: Discussion

Discussion :: Objects and Collections

  1. What will be the output of the program?

     public class Test 
     {    
       private static float[] f = new float[2];     
       public static void main (String[] args)     
       {       
           System.out.println("f[0] = " + f[0]);      
       }
     } 
    

  2. A.

    f[0] = 0

    B.

    f[0] = 0.0

    C.

    Compile Error

    D.

    Runtime Exception

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The choices are between Option A and B, what this question is really testing is your knowledge of default values of an initialized array. This is an array type float i.e. it is a type that uses decimal point numbers therefore its initial value will be 0.0 and not 0


Be The First To Comment