You are on page 1of 1

Java: Inheritance Exercises

Louise Dennis September 28, 2005


Consider the following two Java Classes class Point { public double x,y; public void clear() { this.x = 0; this.y = 0; } } class Pixel extends Point { Color color; } What is the difference between them - in terms of what they do? Suppose you have a program for managing an online library and you have a class for books which includes elds for whether the book is currently in or out of the library (in library) and how many days it will be before it is returned to the library (days returned). There is also a method (taken out) which is run each time a book is taken out of the library and which, among other things changes the value of days returned. How might you use inheritance to distinguish between a short loan and a long loan book? The book class also has a return details method which is used by the search part of the catalogue to return the books details (such as author, whether it is in stock etc.) to a user. The library has some electronic books and in this case they want the details to include a link to the electronic version of the book. How might you use inheritance to do this?

You might also like