Lab 18: Inheritance, extends, super, and Method Overriding


Due Wednesday, December 7 at 11:59 PM

Goals for This Lab

By the time you have completed this work, you should be able to:

Provided files:

Step-by-Step Instructions

Step 1: Copy Over Your Rectangle.java From Lab 7

This lab reuses your Rectangle.java solution you wrote back in Lab 7. Copy over your solution into whatever folder/directory you're working in. Assuming your previous solution worked, you do not need to edit your solution in any way. If you're unsure if your previous solution worked, ask us and we can check it.

Step 2: Download and Open the SubClass.java File

Download the SubClass.java file, and open it in jGrasp (or a text editor of your choice). Note that you should not edit this file, though you will need to be aware of the code it contains.

Step 3: Edit BaseClass.java

Download the BaseClass.java file, and open it in jGrasp (or a text editor of your choice). BaseClass.java contains code that SubClass.java inherits. You will need to add code to BaseClass.java so that SubClass.java will compile, run, and produce the correct result. Example output from SubClass.java with the command-line argument hello is shown below:

hello

Step 4: Edit RectangleWithArea.java

Download the RectangleWithArea.java file, and open it in jGrasp (or a text editor of your choice). You will need to add code to this file so that it compiles and produces the correct output. More details are in the comments in the file. As stated in step 1, this file depends on your Rectangle.java file being in the same folder/directory. Example output from RectangleWithArea.java with the command-line arguments 3 5 is shown below:

Width: 3
Height: 5
Area: 15

Step 5: Download and Open the BaseOverride.java File

Download the BaseOverride.java file, and open it in jGrasp (or a text editor of your choice). Note that you should not edit this file, though you will need to be aware of the code it contains.

Step 6: Edit SubOverride.java

Download the SubOverride.java file, and open it in jGrasp (or a text editor of your choice). You will need to add code to this file so that it compiles and produces no output when run. More details are in the comments in the file.

Step 7: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110 class. Click “Assignments” on the left pane, then click “Lab 18”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:

In addition, if you collaborated with anyone else, be sure to download collaborators.txt and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other three files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.