Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How will you program using java oom.google.com/u/o/C/MTQ5OTYXNDgxODRa tled document Internships-Northr Race Horse-Inheritance Inheritance - Rules to Remember 1. A subclass can add new private instance
How will you program using java
oom.google.com/u/o/C/MTQ5OTYXNDgxODRa tled document Internships-Northr Race Horse-Inheritance Inheritance - Rules to Remember 1. A subclass can add new private instance variables 2. A subclass can add new public or private methods 3. A subclass can override (redefine) inherited methods. 4. A subclass must define its own constructors 5. A subclass cannot access the private members of its superclass. Description A Horse class is defined with the following attributes and behaviors Attributes (instance variables) . name- the name of the horse owner- the owner of the horse . value how much the horse is worth Behaviors (methods) toString returns a string representation of the values stored in a horse object's instance variables Define a RaceHorse class with all of the attributes of the Horse class but with an additional attribute for the number of races a horse has won. Since a race horse is-a a type of horse this relationship can be represented in Java using inheritance. The diagram below illustrates this relationship Horse Race Horse Source Code Open and copy the following workspace to your home directory. Horse Make the following additions and modifications to the RaceHorse class 1. A subclass can add new private instance variables RMartr google.com/u/o/c/MTO5OTYXNDgxODRa ocument- M Internships Northr Race Horse Source Code Open and copy the following workspace to your home directory: Horse Modifications Make the following additions and modifications to the RaceHorse class: 1. A subclass can add new private instance variables. Add an instance variable of type int named numRacesWon 2. A subclass can add new public or private methods. Add an accessor method named getRacesWon Add a mutator method named winRace Override the toString method 3. A subclass can override (redefine) inherited methods. 4. A subclass must define its own constructors. Add a default constructor . . Add a second constructor which includes 4 parameters to initialize the instance variables owner, age, value, and numRacesWon. 5. A subclass cannot access the private members of its superclass Sample Run owner John Wayne Age #3 alue $250000.0 Races won 2 wner Jimmy Stewart Value $325000.0 aces won 8
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