Computer Applications

Is it legal to define local variables with the same identifier in nested blocks?

Encapsulation & Inheritance in Java

3 Likes

Answer

No, it is illegal to define local variables with the same identifier in nested blocks

The local variable declaration space of a block includes any nested blocks. Thus, within a nested block it is not possible to declare a local variable with the same name as a local variable in an enclosing block.

Answered By

2 Likes


Related Questions