Home » JAVA Programming » Arrays » Question
  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    int array1[] = new int[8];
    int array2[] = {5, 8, 7, 6, 9};
    System.out.println(array1.length + " " + array2.length);
    }
    }
    1. 9 5
    2. 5 9
    3. 8 5
    4. 5 8
    5. None of these
Correct Option: C

Arrays in java are implemented as objects, they contain an attribute that is length which contains the number of elements that can be stored in the array. Hence array1.length gives 8 and array2.length gives 5.
output: 8 5



Your comments will be displayed only after manual approval.