- #1

- 3

- 0

Consider the following java code

What is the output

A. 0

B. 1

C. 3

D. No output. A compilation error occurs

The answer is B. I wanna ask why the output shown will not be 3. As the 1 is not equal to 0, should the ' int a ' be modified to 3?

Thank you

Java:

```
int a=1;
if (a != 0)
{
int a=3;
}
System.out.print(a);
```

What is the output

A. 0

B. 1

C. 3

D. No output. A compilation error occurs

The answer is B. I wanna ask why the output shown will not be 3. As the 1 is not equal to 0, should the ' int a ' be modified to 3?

Thank you

Last edited by a moderator: