+ 1

My code not running

class Car { var topspeed = 200 func drive() { print ("Driving at \(topspeed)") } }

13th Nov 2022, 2:07 PM
Emmanuel Pena
17 Respuestas
+ 5
You did not create an instance of Car and you did not call any method/ function.
13th Nov 2022, 2:16 PM
Lisa
Lisa - avatar
+ 2
// create instance of Car var c = Car() c.drive()
13th Nov 2022, 2:22 PM
SoloProg
SoloProg - avatar
+ 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()
13th Nov 2022, 6:38 PM
SoloProg
SoloProg - avatar
+ 2
Emmanuel Pena The curly bracket in line 23 move it to line 18.
13th Nov 2022, 8:18 PM
xrage killer
xrage killer - avatar
+ 2
Thank you so much !!!
13th Nov 2022, 8:23 PM
Emmanuel Pena
+ 2
Solo prog , Thank you . Can you explain why private var ?
13th Nov 2022, 8:49 PM
Emmanuel Pena
13th Nov 2022, 4:59 PM
Emmanuel Pena
0
Its say something wrong with var= topspeed
13th Nov 2022, 4:59 PM
Emmanuel Pena
0
Show me an example on instance
13th Nov 2022, 5:28 PM
Emmanuel Pena
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
13th Nov 2022, 6:09 PM
SoloProg
SoloProg - avatar
0
The link is sending me somewhere else
13th Nov 2022, 6:10 PM
Emmanuel Pena
0
Bro im clicking it its not the playground
13th Nov 2022, 6:34 PM
Emmanuel Pena
13th Nov 2022, 7:03 PM
Emmanuel Pena
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
13th Nov 2022, 9:24 PM
SoloProg
SoloProg - avatar
0
You don't seem to have called any function at all. Call the function and it will run
14th Nov 2022, 2:18 PM
Cedrick Msila
Cedrick Msila - avatar
0
Ouf ! J'avais vraiment besoin de cette appli malheureusement,elle n'est pas français Suis sous le choc
14th Nov 2022, 2:53 PM
Hard Smak's
Hard Smak's - avatar
0
hello world..
15th Nov 2022, 1:18 PM
PASS WORD