+ 1
My code not running
class Car { var topspeed = 200 func drive() { print ("Driving at \(topspeed)") } }
18 Réponses
+ 5
You did not create an instance of Car and you did not call any method/ function.
+ 2
// create instance of Car
var c = Car()
c.drive()
+ 2
// Emmanuel Pena , Hope this helps
https://code.sololearn.com/cDOi89m73C19
class Car {
private var topSpeed = 200
func drive() {
print ("Driving at \(topSpeed)")
}
}
class futureCar : Car{
var topSpeed = 250
override func drive () {
super.drive()
print("Driving at \(topSpeed + 50)")
}
func flying () {
print("flying")
}
}
let Myride = Car()
Myride.drive()
print("*****")
let mynewRide = futureCar()
mynewRide.drive()
mynewRide.flying()
+ 2
Emmanuel Pena
The curly bracket in line 23 move it to line 18.
+ 2
Thank you so much !!!
+ 2
Solo prog ,
Thank you .
Can you explain why private var ?
0
Its say something wrong with var= topspeed
0
Show me an example on instance
0
Emmanuel Pena ,
I made the code better there were a few simple mistakes you need to pay attention because swift is case-sensitive
https://www.sololearn.com/compiler-playground/cDOi89m73C19
0
The link is sending me somewhere else
0
Bro im clicking it its not the playground
0
https://code.sololearn.com/c8FUxYS710rF/?ref=app
Something is missing
0
private
is definitely recommended to use but only in cases when you want that kind of privacy for your properties.
https://stackoverflow.com/questions/60445040/private-variables-in-swift
0
You don't seem to have called any function at all. Call the function and it will run
0
Ouf ! J'avais vraiment besoin de cette appli malheureusement,elle n'est pas français
Suis sous le choc
0
hello world..