Tags

, , , , , ,

Course: Berkeley’s CS 61B: Data Structures.

Lab 5: Practice with Java Inheritance and Java Interfaces

Lab 5 (mirror) gives you needed insight into Java inheritance and prepares you for hw4.

Unlike the previous 4 labs (which IMHO were trivial) this one’s a bit more interesting in that it makes you take a closer look on how exactly inheritance works in Java. You get to poke around and see what you can do and what you can’t do in the relationship between a class, a superclass and an interface.

I decided to just use a different package (folder) for each part of the problem to keep things simple and separate. At a few places, I went a bit beyond the requirements of the lab specs, just to satisfy my curiosity.

Remarks/explanations and answers to the questions are in the sources as comments.

/part1/

Part1.java (view | download)
X.java (view | download)
Y.java (view | download)

/part2/

Part2.java (view | download)
Child.java (view | download)
Parent.java (view | download)
Interface.java (view | download)

/part3/

Part3.java (view | download)
Child.java (view | download)
Parent.java (view | download)
Interface.java (view | download)

/part4/

Part4.java (view | download)
X.java (view | download)
Y.java  (view | download)

Or download lab5.zip

Enjoy!

Advertisements