Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAryan Kumar
96 PointsIf a change happens to the base class, do those the changes occur in the sub class as well?
So, let's say I have class Vertebrate and it's derived class Mammal. If I change something in Vertebrate, An example, "Vertebrate.HasBackBone = false;", does "Mammal.HasBackBone" become false too or does it remain true?
1 Answer
Steven Parker
231,198 PointsI would say "yes", with qualifications:
Your examples don't seem to fit the question. For starters, if "Vertebrate" is a class, you would not be likely to write "Vertebrate.HasBackBone = false
". You might have a class instance, for example named "animal", and you might write "animal.HasBackBone = false
". But that would look the same whether "animal" was an instance of "Vertebrate" or if it was an instance of "Mammal".
Perhaps a better example would be adding a new field or property to the base class. So if you added a new property called "HasBrain
" to the Vertebrate class, it would also be available in the Mammal class.