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 2.0 Class Inheritance Overriding Properties

Von Chucwuemeca
Von Chucwuemeca
4,746 Points

I don't see how we arrived at super.init

I don't see how we arrived at super.init. To me it seems that 'super' is a arbitrary variable.

class SuperEnemy: Enemy { // Inheritance - giving a class the properties of another class. let isSuper: Bool = true

/////////////////////////////////// Override Init ///////////////////////////////////

override init(x: Int, y: Int) {  // overiding the initializer of the superclass w/ own.
    super.init(x: 4, y: 3)
}

}

1 Answer

Hi Von,

It sort of is arbitrary but it's also a common convention in Object-Oriented Programming. super is a convenient reference to a given class's parent-class. You need to call the init method of your parent-class in your child-class in order to inherit the parent-class's data and methods. That's how inheritance works.