Computer Applications

Which of the following is a valid array declaration statement to store the Gender of 80 employees [ 'M'-male, 'F'-female, 'T'-transgender ]?

  1. char gender = new char[80];
  2. char gender[] = new char[80];
  3. char gender[80];
  4. char gender[80] = new char[ ];

Java Arrays

3 Likes

Answer

char gender[] = new char[80];

Reason — In Java, arrays must be declared with the type followed by square brackets [] either before or after the variable name. The correct syntax to declare a character array of size 80 is char gender[] = new char[80];.

Answered By

3 Likes


Related Questions