Examveda
Examveda

What is the result of compiling and running the following code?
public class Test{
        public static void main(String[] args){
                int[] a = new int[0];
                System.out.print(a.length);
        }
}

A. 0

B. Compilation error, arrays cannot be initialized to zero size.

C. Compilation error, it is a.length() not a.length

D. None of the above

Answer: Option A


Join The Discussion

Comments ( 1 )

  1. Limali Sahoo
    Limali Sahoo :
    3 years ago

    As we know counting is done from 1 when length is calculated. then why answer is 0.

Related Questions on Array