Use an Inherited Getter in a Subclass
easyQuestion 507Guitar extends Instrument, so every guitar already has the public method getName() without writing it again. The field name is private in Instrument, which means code inside Guitar cannot read it directly. Complete strum().
Requirements:
1. strum() returns the guitar's name followed by the words goes strum, for example Fender goes strum.
2. Read the name through the inherited getName(). Do not add a second name field to Guitar.
The Instrument class is provided. Do not change it.
Do NOT write a main method.
Expected output
Fender Fender goes strum
= newline. The output ends with a newline, so print one after the last line.
Hints3 available
Sign in to use hintsTopics
InheritanceClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.