The class TrafficLights
{
Void shine ()
{
System. The out. Println (" traffic lights shine ");
}
}
The class YellowTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" yellow light glows red ");
}
}
The class GreenTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" green light glows red ");
}
}
The class RedTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" the red light glows red ");
}
}
CodePudding user response:
The class TrafficLights{
Void shine ()
{
System. The out. Println (" traffic lights shine ");
}
}
The class YellowTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" yellow light glows red ");
}
}
The class GreenTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" green light glows red ");
}
}
The class RedTrafficLight extends TrafficLights
{
Void shine ()
{
System. The out. Println (" the red light glows red ");
}
Public static void main (String [] args)
{
TrafficLights traffic=new TrafficLights ();
YellowTrafficLight Yellow=new YellowTrafficLight ();
GreenTrafficLight Green=new GreenTrafficLight ();
RedTrafficLight Red=new RedTrafficLight ();
String Vehicle []={" traffic ", "Yellow", "Green", "Red"};
System. The out. Println (" traffic lights: ");
Traffic. Shine ();
System. The out. Println (" traffic lights: ");
Yellow. Shine ();
System. The out. Println (" traffic lights: ");
Red. Shine ();
System. The out. Println (" traffic lights: ");
Green. Shine ();
}
}
Thanks to this topic later to the bosses can see optimize code yes thank you
CodePudding user response:
TrafficLights [] array={new TrafficLights (), new YellowTrafficLight (), new GreenTrafficLight (), new RedTrafficLight ()}CodePudding user response:
Ok thank you