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 trial

iOS Build a Simple iPhone App with Swift Getting Started with iOS Development Recap of Object Oriented Swift

Subclass initialization: Is the question/answer in this quiz correct?

I'm doing the "Build a Simple iPhone App with Swift 3" course and one of the quiz questions is "When we initialize a subclass, we first need to initialize the properties in our base class, then call the super class' initializer".

I put false, as I thought it was a trick question... But it says I was wrong.

Isn't the base class the same as the super class in the example above?

2 Answers

Apples documentation describes a base class as “a class that does not inherit from another class”.

It defines a superclass as a “class from such the subclass inherits from”

I’d say that almost certainly they are exactly the same thing.

I think maybe the “super class” should actually say “sub class” in the question? That would explain the question correctly and also give the answer of True.

Hmm... I thought that might be the case, I'll see if I can try flagging it to someone so they can change it (or educate me on why it is correct).

Cheers!

Once you find out, be sure to let me know!

Actually, reading it again...

The base class doesn’t inherit from ANY class.

Superclass CAN inherit from another superclass!

For example...

BASE CLASS -> SUPERCLASS -> SUBCLASS

If you create another subclass that inherits from a previous subclass, that subclass becomes a superclass!

So therefore, the question is saying.. first we must initialise the values in the base class, which is true. Then you have to initialise the superclass (which can be different to base class as outlined above) , which is also true.

Even in that case though, aren't we always supposed to initialize the values of the subclass first? I thought that was the rule.

Yes you are completely correct...

So I guess the question must be wrong then! Hmm.. haha.. odd one.

I'll let you know what they say :)

Hey mate! Pasan got back to me, turns out the question itself was incorrect!

Oh! Haha! Thanks for letting me know mate! Nice work.