Final answer:
To demonstrate the use of polymorphism with the Line class and its subclasses, create objects of the subclasses and assign them to the Line class reference variable 'line'. Call the 'draw()' method on the 'line' object to draw the selected line type.
Step-by-step explanation:
To demonstrate the use of polymorphism with the Line class and its subclasses, we can create three subclasses: SolidLine, DashedLine, and DottedLine. In the code provided, we can complete the underlined sections as follows:
- line = new SolidLine(coord1, coord2);
- line = new DashedLine(coord1, coord2);
- line = new DottedLine(coord1, coord2);
- This allows us to create objects of different subclasses and assign them to the Line class reference variable 'line'. After the user selects the line type, we can call the 'draw()' method on the 'line' object to draw the selected line type.