1
public class Test {
    public static void main(String[] args) {
        int a = 5;
        switch (a) {
            case 1:
                double b = 10;
                System.out.println(b);
                break;
            case 5:
                b = 20;
                System.out.println(b);
                break;
            default:
                break;
        }
    }
}

I wonder that why the code could be run? It looks like the b has no chance to be declared.

Paul Zhang
  • 305
  • 2
  • 7

0 Answers0