Search⌘ K

Solution Review: Manage the Sign Boards

Understand how to apply polymorphism principles in Java by examining the TrafficSign class and its subclasses such as StopSign, NoBicycleSign, and WorkersAhead. Learn to use inheritance, constructors, and method overriding to create flexible and reusable code relevant to the AP Computer Science exam.

The TrafficSign class

Rubric criteria

First, look at the TrafficSign class.

Java
public class TrafficSign
{
// private instances
private String name;
private String code;
// constructor
public TrafficSign(String name, String code)
{
this.name = name;
this.code = code;
}
public void Description()
{
System.out.println("Sign's description");
}
}

Rubric-wise explanation


Point 1:

We add the header of TrafficSign at line 1.

Point 2:

Initially, we create private instances: name and code. Each sign has a name and a code associated with it. Next, at line 8, we design its constructor.

Point 3:

Look at line 14. We create the header of the Description() ...