I'm trying to figure out how to do the following:
Class A has data items:
car
bike
phone
cup
Class B inherits Class A but only the data items car and bike. Data items phone and cup are not available to Class B
Class B adds
tire
handlebars
bell
helmet
Class C inherits from Class B, it also has access to data items car and bike from Class A, tire and handlebars from Class B (but not bell and helmet).
So here is where I'm stuck. It seems like inheritance will allow Class B access to all data items in Class A. That is, nothing can be hidden from Class B unless Class A is private to Class B in which case all data items from Class A are unavailable to Class B.
So, what to do when you want to pass along some access to some data items but not all data items from a super class to a sub class and down another sub class as in the Class A, B, and C example above?
Class A has data items:
car
bike
phone
cup
Class B inherits Class A but only the data items car and bike. Data items phone and cup are not available to Class B
Class B adds
tire
handlebars
bell
helmet
Class C inherits from Class B, it also has access to data items car and bike from Class A, tire and handlebars from Class B (but not bell and helmet).
So here is where I'm stuck. It seems like inheritance will allow Class B access to all data items in Class A. That is, nothing can be hidden from Class B unless Class A is private to Class B in which case all data items from Class A are unavailable to Class B.
So, what to do when you want to pass along some access to some data items but not all data items from a super class to a sub class and down another sub class as in the Class A, B, and C example above?