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 trialJUN MENG
10,249 Pointsswift_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οΌ
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
miikis
44,957 PointsHi 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:
- Car class is missing a closing bracket
- You made numberOfSeats a constant. Which is fine. But then you try to change it in your init method. That's a no-no.
- Your init method needs an override keyword since you're overriding the super class's init.
- You need to call super.init:withDoors:andWheels in your Car class. It's part of the inheritance process.
- The arguments to super.init:withDoors:andWheels need to come from somewhere... so the Car class's init method's parameters need to change.
- 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.