7 | Open the dome-v2 project. Add a class for video games to the project. Create some video game objects and test that all the methods work as expected. | Done, here are the class' fields: |
8 | Order these items into an inheritance hierarchy: apple, ice cream, bread, fruit, food-item, cereal, orange, dessert, chocolate mousse, baguette. | Done: |
9 | In what inheritance relationship might a touch pad and a mouse be? | Computer Devices |
10 | | Rectangle would be the parent class of square, as a square is a rectangle, but a rectangle is not a square, simply that. |
11 | Assume we have four classes: Person, Student, Teacher & PhDStudent. Teacher and Student are both subclasses of Person. PhDStudent is a subclass of Student. Which of the following assignments are legal and why? Person p1 = new Student(); Person p2 = new PhDStudent(); PhDStudent phd1 = new Student(); Teacher t1 = new Person(); Student s1 = new PhDStudent(); s1 = p1; s1 = p2; p1 = s1; t1 = s1; s1= phd1; phd1 = s1; | a) legal b) legal e) legal g) legal h) legal j) legal k) legal because sub-types can be assigned to super classes, or to their own class, but super classes can't be assigned to sub-classes, it's like saying a square gets new rectangle, it's preposterous. |
12 | Test your answers to the previous question by creating the classes mentioned in that exercise, and trying it out in BlueJ. | Done, this is the set up i used: |
13 | What has to change in the Database class when another item subclass (for example class VideoGame) is added? Why? | Nothing, because VideoGame is an Item, and therefore Item will allow VideoGame to be added to the ArrayList of Database without further coding. |
14 | Use the documentation of the standard class libraries to find out about the inheritance hierarchy of the collection classes. Draw a diagram showing the hierarchy. | Unable to find the section on standard class libraries. |
15 | Go back to the lab-classess project from chapter 1. Add instructors to the project. Use inheritance to avoid code duplication between students and instructors. | I attempted to add some methods to the project as well but received some compiling errors: |
16 | Draw an inheritance hierarchy representing parts of a computer system (processor, memory, disk drive, CD drive, printer, scanner, keyboard, mouse, etc.) | |
17 | Look at the code below. You have four classes (O,X,T and M) and a variable of each of these. O o; X x; T t; M m; The following assignments are all legal. m = t; m = x; o = t; The following assignments are all illegal. o = m; o = x; x = o; What can you say about the relationships of these classes? | They have no relationships, therefore it makes no sense whatsoever to assign them to one another. |
18 | Draw an inheritance hierarchy of AbstractList and all its (direct and indirect) subclasses, as they are defined in the Java standard library. | Done: |
Thursday, 4 November 2010
Chapter 8 8.7-End
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment