13.9 Exercises


13.9 Exercises

  1. Explain the differences and similarities between interfaces and abstract classes. Give two examples.

  2. Explain the differences and similarities between polymorphism and overloading. Give examples.

  3. Explain the differences between implementing an interface and overriding the methods of an abstract class. Give two examples.

  4. Explain the differences between function overriding and polymorphism. Give two examples.

  5. Does function overriding imply polymorphism? Is it possible to override one or more functions without using polymorphism? Explain and give an example.

  6. Is it possible to define an abstract base class and one or more subclasses without using polymorphism? Explain and give an example.

  7. Which is the most straightforward way to overcome the Java (and KJP) limitation of only supporting single inheritance? Give an example.

  8. Enhance the problem with base class Gfigures discussed in Section 13.2.1 and illustrated in Figure 13.1. Add the capability to the geometric figures to draw themselves on the screen using dots and dashes. Define an interface at the top of the hierarchy. Write the complete program.

  9. A company has several groups of employees, executives, managers, regular staff, hourly paid staff, and others. The company needs to maintain the data for all employees in a list. Design a solution to this problem that uses a heterogeneous array of employee objects. Use an abstract base class and apply polymorphism to process the list (array). Write the complete program.

  10. Repeat the previous problem defining an interface instead of an abstract base class. Compare the two solutions to the problem.

  11. Design a hierarchy for animals. Find some behavior in all animals that is carried out in different manners (eat, move, reproduce, or others). Define the top-level animal category with an abstract base class and one or more interfaces. Define and implement the subclasses. Write the complete program.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net