Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Class Inheritance Creating a Subclass

swift_lint.swift:20:7: note: in declaration of 'Car' class Car: Vehicle {

What is this:::

swift_lint.swift:20:7: note: in declaration of 'Car' class Car: Vehicle {

can I fix it?

objects.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 {
let  numberOfSeats: Int = 4
init (numberOfSeats: Int){
self.numberOfSeats = numberOfSeats
}
let someCar = Car(numberOfSeats: 4)

1 Answer

Mikis Woodwinter
Mikis Woodwinter
44,939 Points

Hi Jun,

There are a number of things wrong with your code. Maybe think about going back and re-watching the course. Here's a list of some of your errors:

  1. Car class is missing a closing bracket
  2. You made numberOfSeats a constant. Which is fine. But then you try to change it in your init method. That's a no-no.
  3. Your init method needs an override keyword since you're overriding the super class's init.
  4. You need to call super.init:withDoors:andWheels in your Car class. It's part of the inheritance process.
  5. The arguments to super.init:withDoors:andWheels need to come from somewhere... so the Car class's init method's parameters need to change.
  6. After you do the above, you'll need to change the way you initialize Car when you assign it to someCar.

Actually, that seems like a pretty exhaustive list of errors. But, it might not be.