Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
