
10.6 Polymorphism 699
16 figuresList.add( new Circle( 160, 110, Color.RED, 10 ));
17
18 figuresList.add( new Square( 150, 140, Color.BLACK, 40 ));
19 figuresList.add( new Circle( 160, 150, Color.YELLOW, 10 ));
20
21 figuresList.add( new Square( 150, 180, Color.BLACK, 40 ));
22 figuresList.add( new Circle( 160, 190, Color.GREEN, 10 ));
23 }
24
25 public void paint( Graphics g )
26 {
27 for ( Figure f : figuresList )
28 f.draw( g );
29 }
30 }
EXAMPLE 10.19 Traffic Light Using Polymorphism
10.10.1 Multiple Choice Exercises
Questions 7,10,11
10.10.4 Identifying Errors in Code
Question 31
10.10.5 Debugging Area
Questions 33,34,35
Skill Practice
with these end-of-chapter ...