Select the invalid declaration from the lines of Java code below
int zebraCnt = 40000;
long birdCnt = 222_222_222_222_222L;
a. float avg = 23.5;
b. double avg = 98.32121;
c. None of the above. d. All are legal declaration.

Respuesta :

Answer:

float avg = 23.5;

Explanation:

Given

The declarative statements

Required

Determine which of them is invalid

Analyzing them one after the other;

int zebraCnt = 40000;

This statement is valid as zebraCnt is correctly declared as type integer

long birdCnt = 222_222_222_222_222L;

This statement is valid as birdCnt is correctly declared as type long

float avg = 23.5;

This statement is invalid as avg is incorrectly declared as type float.

To correctly declare avg, you either change the datatype to double: as follows;

double avg = 23.5;

or append f to the declaration; as follows

float avg = 23.5f;

double avg = 98.32121;

This statement is valid as avg is correctly declared as type double

Hence, the incorrect declarative statement is float avg = 23.5;