Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Inheritance Question 7 (a) Arrange the following classes in a class hierarchy as a diagram to show where behaviour is shared and where it is
Inheritance Question 7 (a) Arrange the following classes in a class hierarchy as a diagram to show where behaviour is shared and where it is extended: Person, PublicServant, Senator, Driver, President, Politician 3 marks] (b) Why would we want to inherit behaviour and state from another class? Illustrate your answer with an example that clearly shows the benefits of this approach. 3 marks] (c) You have defined a class Vehicle and now wish to define a new class HoverCraft that inherits from Vehicle and adds a single public function with this signature: void Hover Write the C+ Vehicle. Make sure that you explicitly declare the default constructor. declaration for HoverCraft that clearly shows the inheritance from 4 marks] (d) In the previous part, Vehicle has an integer variable weight defined as part of the class. What is the access modifier that must be used with weight if we want it available to HoverCraft but not to other classes that have not inherited Vehicle? [2 marks] [Total for Question 7: 12 marks]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started