Java switch : variable declaration and scope

后端 未结 7 671
予麋鹿
予麋鹿 2020-12-11 03:14

How does the Java compiler handle the following switch block ? What is the scope of the \'b\' variable ?

Note that the \'b\' variable is declared only in the first b

7条回答
  •  萌比男神i
    2020-12-11 03:45

    in your code if a is not equal to 0 b will never be initialized. you should define b before the switch statement.

提交回复
热议问题