โ 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: 1 Do NOT write a main function.
Expected Output:
1
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.