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 Object-Oriented Swift Class Inheritance Overriding Properties

NIKOLA RUSEV
NIKOLA RUSEV
5,293 Points

subclass subsubclass

i just want to ask you is it possible to have a subsubclass? i mean is there chance one subclass be a superclass for another subclass?

2 Answers

I've tried that by creating a subclass "Boss" and it works (I just changed isSuper to variable so I could assign a new value to it)

class Boss: SuperEnemy {
    let isBoss: Bool = true
    override init(x: Int, y: Int) {
        super.init(x: x, y: y)
        self.isSuper = false
    }
}

let theBoss = Boss(x: 2, y: 2)
theBoss.isSuper // returns false

Yes, I believe you can.