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 Creating a Subclass

Ben Masel
Ben Masel
2,004 Points

Plz help with this code challenge, I am VERY confused

I am only 11 yrs old and having trouble with swift, i want to keep doing Treehouse but i might not be able to cope! Please help me with inheritance and sub classes and plz help finish this Code Challenge, Also what is an instance again? I always forget. Thnx

classes.swift
class Vehicle {
    var numberOfDoors: Int
    var numberOfWheels: Int

    init(withDoors doors: Int, andWheels wheels: Int) {
        self.numberOfDoors = doors
        self.numberOfWheels = wheels
    }
}

// Enter your code below
class Car: Vehicle {
var numberOfSeats: Int = 4
let someCar = ???
}

2 Answers

John Roque Jorillo
John Roque Jorillo
13,117 Points

class Car: Vehicle { var numberOfSeats: Int = 4 }

let someCar = Car(withDoors: 4, addWheels: 4)

Here, hope this will help.

11 years old?!! keep it up.

Paul Karim
Paul Karim
3,428 Points

Well in your code challenge you have a class named Car right? Well when you create an object using that class that object becomes an "instance" of the Car class. So, let lamborghini = Car(withDoors: 2, andWheels: 4), the constant lamborghini would be the instance.

Hope that helps with your instance question :)

EDIT: Also, in your code challenge the let someCar = Car(withDoors: 4, andWheels: 4 ) needs to be outside of the Car classes code block. So type it after the last }