← Back to Inheritance
Question 438
Age Check Using an Inherited Field
Age Check Using an Inherited Field
A derived class can build new logic on top of a field it inherits. Base classPersonhas a protectedint ageand a constructorPerson(int a). Create a derived classCitizenwith: 1. a constructorCitizen(int a)that forwardsatoPerson2. a methodbool canVote() constthat returns whether the inheritedageis at least 18 The runner prints the boolean (C++ prints1for true,0for false). For age 20 it prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
1= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.