16.1: no project
Look at the code below. You have four classes (O, X, T and M) and a variable containing each of these.
O o;
X x;
T t;
M m;
The following assignments are all legal (assume they all compile):
m = t;
m = x;
o = t;
The following assignments are all illegal (they cause comiler errors):
o = m;
o = x;
x = o;
What can you say about the relationships of these classes? Draw a class digram showing the inheritance hierarchy.
(Based on Barnes & Kolling ex 8.17)
16.2: DoME-v2 project
Create an object of class DVD in your project, and then invoke the toString method from the Object sub-menu in the object's popup menu.
(Based on Barnes & Kolling ex 9.6)
16.3: DoME-v3 project
Include code 9.2 (page 267) in both classes CD and DVD. When run with appropriate data, the results printed should match fig 9.9 (page 272).
(Based on Barnes & Kolling text)
16.4: DoME-v3 project
Re-order the statements in the CD and DVD print methods so that it prints details as shown in fig 9.10 (page 273).
(Based on Barnes & Kolling ex 9.7)
16.5: no project
Assume you see the following lines of code:
Device dev = new Printer();
dev.getName();
Printer is a subclass of Device. Which of these classes must have a definition of method getName for this code to compile?
(Barnes & Kolling ex 9.12)
16.6: no project
In the same situation as in the previous exercise, if both classes have an implementation of getName, which one will be executed?
(Barnes & Kolling ex 9.13)
16.7: no project
Assume you write a class Student, which does not have a declared superclass. You do not write a toString method. Will the following lines of code compile? Why?
Student st = new Student();
System.out.println(st);
(Based on Barnes & Kolling ex 9.15)