Answered step by step
Verified Expert Solution
Question
1 Approved Answer
When a subclass inherits from a superclass, it also inherits its methods; however, it can also override the superclass methods ( as well as declare
When a subclass inherits from a superclass, it also inherits its methods; however, it can also override the superclass methods as well as declare and implement new ones
Consider the following Sports class given. Next, we create a Soccer class that inherits from the Sports class. We can override the getName getPlayers & printTeamMembers methods and return a different, subclassspecific string.
We will return "Overwritten Soccer" in getName in getPlayers and make it such that printTeamMembers returns the same string as Sports but with its new values.
Test cases:
For all cases assume we have variables sports SportsFootball and soccer SoccerSoccer
Test: Calling getName for a soccer returns "Overwritten Soccer" and for sports returns "Football".
Test: Calling getPlayers for a soccer returns and for sports returns
Test: Calling printTeamMembers for a soccer returns "Each team has players in Overwritten Soccer" and for sports returns "Each team has players in Football".
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