Skip to content

Commit 9284d32

Browse files
committed
Quick edits in inheritance notes.
1 parent 09e1fcc commit 9284d32

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

source/code/projects/Vehicle/Vehicle/Bike.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ public class Bike : Vehicle
55
public Bike()
66
{
77
ForkLength = -1;
8-
SetNOW(2); // or base.setNOW(2);
8+
SetNOW(2);
9+
// or
10+
// base.SetNOW(2);
911
}
1012

1113
public Bike(string cP, double flP)

source/code/projects/Vehicle/Vehicle/Vehicle.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
public class Vehicle
23
{
34
public string Color { get; set; }
@@ -9,7 +10,8 @@ public void SetNOW(int nowP)
910
numberOfWheels = nowP;
1011
else
1112
numberOfWheels = -1;
12-
// We could also decide to throw an exception here.
13+
// We could also decide to throw an exception here, using e.g.
14+
// throw new ArgumentException();
1315
}
1416

1517
public Vehicle()
@@ -22,6 +24,8 @@ public Vehicle(string cP, int nowP)
2224
{
2325
Color = cP;
2426
numberOfWheels = nowP;
27+
// We could also use our SetNOW method, as follows:
28+
// SetNOW(nowP);
2529
}
2630

2731
public override string ToString()

source/lectures/oop/inheritance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Note:
4949
and the `Vehicle` `Color` accessor will be used, since `Bike` does not have an accessor for `Color`.
5050
5151
- Implicitly, the `Bike()` constructor starts by calling the `Vehicle()` constructor, so that `Color` and `numberOfWheels` are actually set to `"undefined"` and `-1`, respectively.
52-
- That `SetNOW` into the `Bike()` constructor actually refers to the `SetNOW` method in the `Vehicle` class. A way of being more explicit would have been to write `base.SetNOW` instead of `SetNOW`. In either case, the value `-1M` is overriden by `2` (since every bike has 2 wheels).
52+
- That `SetNOW` into the `Bike()` constructor actually refers to the `SetNOW` method in the `Vehicle` class. A way of being more explicit would have been to write `base.SetNOW` instead of `SetNOW`. In either case, the value `-1` is overriden by `2` (since every bike has 2 wheels).
5353
- The `: base(cP, 2)` instructs to call the
5454
5555
`Vehicle(string cP, int nowP)`

0 commit comments

Comments
 (0)