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 trialmatthattingtonworrall
3,810 PointsWhy would I override init method in a subclass, in the real world
I understand why you would add a new init method to a subclass if you added new properties. But why would you simply override the init method of a base class. Is it just if you want to change what happens in the base init?
1 Answer
Mitch Little
11,870 PointsHi Matt,
Overriding the initialiser in the subclass can be useful for as you said to add new stored properties, but also to change the way certain stored properties are initialised as another example.
Overriding the designated initialiser does not affect the base class. The base class is initialised by calling super.init.
I hope this help out a little and I'm sure you'll discover new examples down the line.
All the best,
Mitch
matthattingtonworrall
3,810 Pointsmatthattingtonworrall
3,810 PointsThanks Mitch. That has cleared up some confusion!