@@ -31,7 +31,7 @@ class Vehicle
31
31
class Bicycle : Vehicle
32
32
{
33
33
// We'll make this a 2-wheeled vehicle
34
- init ( )
34
+ override init ( )
35
35
{
36
36
super. init ( )
37
37
numberOfWheels = 2
@@ -46,7 +46,7 @@ bicycle.description()
46
46
class Tandem : Bicycle
47
47
{
48
48
// This bicycle has 2 passengers
49
- init ( )
49
+ override init ( )
50
50
{
51
51
super. init ( )
52
52
maxPassengers = 2
@@ -61,7 +61,7 @@ class Car: Vehicle
61
61
var speed : Double = 0.0
62
62
63
63
// New initialization, starting with super.init()
64
- init ( )
64
+ override init ( )
65
65
{
66
66
super. init ( )
67
67
maxPassengers = 5
@@ -143,21 +143,21 @@ automaticCar.gear
143
143
// ------------------------------------------------------------------------------------------------
144
144
// Preenting Overrides
145
145
//
146
- // We can prevent a subclass from overriding a particular method or property using the '@ final'
146
+ // We can prevent a subclass from overriding a particular method or property using the 'final'
147
147
// keyword.
148
148
//
149
- // @ final can be applied to: class, var, func, class methods and subscripts
149
+ // final can be applied to: class, var, func, class methods and subscripts
150
150
//
151
151
// Here, we'll prevent an entire class from being subclassed by applying the . Because of this,
152
- // the @ finals inside the class are not needed, but are present for descriptive purposes. These
153
- // additional @ finals may not compile in the future, but they do today:
154
- @ final class AnotherAutomaticCar : Car
152
+ // the finals inside the class are not needed, but are present for descriptive purposes. These
153
+ // additional finals may not compile in the future, but they do today:
154
+ final class AnotherAutomaticCar : Car
155
155
{
156
156
// This variable cannot be overridden
157
- @ final var gear = 1
157
+ final var gear = 1
158
158
159
159
// We can even prevent overridden functions from being further refined
160
- @ final override var speed : Double
160
+ final override var speed : Double
161
161
{
162
162
didSet { gear = Int ( speed / 10.0 ) + 1 }
163
163
}
0 commit comments