extends
, super
, and Method OverridingDue Wednesday, December 7 at 11:59 PM
By the time you have completed this work, you should be able to:
super
in subclass constructors to initialize base classesextends
to make a subclass inherit from a base classBaseClass.java
SubClass.java
RectangleWithArea.java
BaseOverride.java
SubOverride.java
collaborators.txt
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.
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.
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
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
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.
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.
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:
BaseClass.java
RectangleWithArea.java
SubOverride.java
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.