CST2641 Advanced Java I
Lab Week 3


Lab 6

Interfaces are even more abstract than classes.  Interfaces are a template for a class.  Interfaces are descriptions of variables and methods which any class must provide if it implements this interface.  A subclass has only one superclass, but can implement many interfaces, providing the subclass defines variables and methods for all its interfaces.

Information for constructing an interface can be found in Chapter 6 - Core Java Vol I and Chapter 27 - Java for Students.

Exercises

Exercise 6.1

Using the program 5.1 that you wrote previously, write an interface Prism which provides methods to set the height of the prism, to return the height of the prism, and to return the volume of the prism.

Then write a class RectangularPrism which inherits from the Rectangle class, adds a height attribute and which implements the Prism interface.  You should define a suitable constructor method for this class.

Add some draw.Strings to test your results.