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

Ced I
Ced I
999 Points

Question wording confusion

In the last sentence of this problem, it says: "Once you've implemented the Car class, create an instance and assign it to a constant named someCar." But in order create an instance of this new class, we need to pass in the parameters that it requires but the prompt doesn't give us any values to pass in. Do you want us to just pass in any values we feel like? Or is there a way to create an instance of a class without passing in any parameters that I missed? Thanks!

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 = Car()

1 Answer

Hi there,

Just pass in some values that you create:

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

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

That works fine!

Steve.

Ced I
Ced I
999 Points

Thanks Steve! I don't know if you control this but the prompt should be more explicit about letting us put in any parameters we like when creating a new instance. Or they should just give us some values to put in. Just a suggestion!

Hi Ced,

Thanks for the input. I don't control that side of things at all, I must say.

It's really difficult to balance every student's different learning styles and needs. Some like to be walked through each aspect; I tend in that direction. Others want less leading and need to learn by experimentation. Both work for different people at different times.

I'd suggest trying to complete the challenge and if you run into problems, shout on the Community pages. Someone will help. If you get no response you can always @ mention me; I'll reply as quickly as I am able.

Steve.