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

Vladimir Ulyanov
Vladimir Ulyanov
14,023 Points

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

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

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.

Vladimir Ulyanov
Vladimir Ulyanov
14,023 Points

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!

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

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

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

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.

Vladimir Ulyanov
Vladimir Ulyanov
14,023 Points

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

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

Yes you are completely correct...

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

Vladimir Ulyanov
Vladimir Ulyanov
14,023 Points

I'll let you know what they say :)

Vladimir Ulyanov
Vladimir Ulyanov
14,023 Points

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

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

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