This code will cause a compile error because of a duplicate variable declaration
switch (number)
{
   case 1:
       String result = "Hello";
       break;
   case 2:
       String result = "Goodbye"; // redeclaration of String result
       break;
}
This is because the scope of variable declarations inside the case clauses is the scope of the containing switch statement and program control can pass through more than one case clause (like a logical OR of several cases)
switch (number)
{
   case 1:
   case 2:
       String result = "OK";
       break;
   case 3:
       String result = "NOT OK"; // more obvious redeclaration of String result
}
In order to avoid the error you can use braces to declare a local scope so the variable declarations do not clash:
switch (number)
{
   case 1:
         {
           String result = "Hello"; // declared in local scope
         }
       break;
   case 2:
         {
           String result = "Goodbye"; // redeclaration of String result
         }
       break;
}
Obviously you will need to do something with the variable before the end of local scope or its value will be lost!
A better solution if you are not returning a value from the case statement would be to declare the variable outside the switch to avoid redeclaration and local scope problems:
String result = null;
switch (number)
{
   case 1:
         result = "Hello";
       break;
   case 2:
         result = "Goodbye";
       break;
}