KnowledgeBoat Logo
|

Computer Applications

Which of the following is the correct usage?

  1. int a[-40]
  2. int a[40]
  3. float a[0 - 40]
  4. None

Java Arrays

256 Likes

Answer

None

Reason — In Java, an array is created using the new keyword, and its size is specified only at the time of creation, for example:
int[] a = new int[40];

Statements like int a[40]; follow C/C++ syntax and are not valid in Java.
Also, an array size cannot be negative.

Therefore, none of the given statements is a correct array declaration in Java.

Answered By

89 Likes


Related Questions