public class Examples {
void redSignal() {
System.out.println("Red");
}
void yellowSignal(){
System.out.println("Yellow");
}
void greenSignal(){
System.out.println("Green");
}
void otherColor() {
System.out.println("Not a Valid Color");
}
public static void main(String[] args) {
Examples act=new Examples();
String color= "Yellow";
switch(color) {
case "Red":
act.redSignal();
break;
case "Yellow":
act.yellowSignal();
break;
case "Green":
act.greenSignal();
break;
default:
act.otherColor();
}
}
}
O/P:
Yellow
Top comments (0)