Answered step by step
Verified Expert Solution
Link Copied!

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, subclass-specific string.
We will return "Overwritten Soccer" in getName(),11 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 = Sports("Football",53) and soccer = Soccer("Soccer",22)
Test1: Calling getName() for a soccer returns "Overwritten Soccer" and for sports returns "Football".
Test2: Calling getPlayers() for a soccer returns 11 and for sports returns 53.
Test3: Calling printTeamMembers() for a soccer returns "Each team has 11 players in Overwritten Soccer" and for sports returns "Each team has 53 players in Football".

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago