Question
1. Create a subclass Create a sub class that inherits everything from your base class. (For example, if Car is the base class then SportsCar
1. Create a subclass
Create a sub class that inherits everything from your base class. (For example, if Car is the base class then SportsCar could be your sub class) [1 point]
Provide at least one additional attribute to your subclass [1 point]
Create gettter/setter methods for it.
Create a default constructor for the subclass, that uses super to call the base class default constructor. [1 point]
It should set all attributes in the subclass as well as the super class to default values
Create a parameterized constructor for the subclass, that uses keyword super to pass the inherited parameters to the base class. [1 point]
It should set all attributes in the subclass as well as the super class to the values that are passed in to the constructor.
Override the display() method to print out all the instance variable values from the base class, and also from the sub class. [1 point]
It should also have a method called toString and printToFile (see instructions in part 2 below)
2. Create an Interface
Create an interface called Printable that has the following methods declared: display(), printToFile() and toString().
Make your subclass above implement the interface. This includes writing the bodies of all 3 methods. You should already have a display method, so you need to implement the other 2 methods [1 point]
Override the toString method in the subclass in part 1 [1 point]
Implement the printToFile method in the subclass in part 1. The method should be able to append to a file, not overwrite it. [1 point]
3. Update main method
In your main method, create 2 new object using your subclass Create one object using the no-arg (default) constructor of your sub-class. [1 point]
Call the set methods to set all attribute data associated to that object.
Create one object using the parameterized constructor of your sub-class. [1 point]
Create an ArrayList of all your objects, including the original ones created using the Super class and the new ones created using the Base class. [1 point]
Loop (iterate) through each object calling the printToFile method. [1 point]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started