Reputation: 31
I'm new in programming and I'm studying inheritance principle, I'm working on an exercise that requires me to create a parent class called "normalClock", the attributes include the time and AM or PM, I need to create a child class that inherits from "normalClock" but this one only works with AM time, only displaying the morning time, is it possible for me to modify the attribute from the parent class.. lets say remove "PM" without breaking the rules on inheritance? I don't want to change anything from the parent class I just want to know if its something that can be done in the child class.
thanks in advance
Upvotes: 0
Views: 453
Reputation: 13589
This is not possible (aside from some really messy template/macro hacks) in C++.
Furthermore, the fact that you want to do this in the first place indicates that your design is likely wrong. Your "AM only" clock violates the Liskov Substitution Principle - that is, code that works on normalClock
s should also work on morningClock
s, but this design would cause the two types to be incompatible.
Upvotes: 3