Skip to content

Commit 82e30f5

Browse files
committed
Added solution to Quiz #6.
1 parent 1a5e47e commit 82e30f5

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

source/solutions/oop/inheritance.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ tags:
1616
- [ ] `over`
1717
- [ ] `inherits`
1818

19+
#. Inheritance is …
20+
21+
- [x] … a way of implementing a class by re-using another class' code.
22+
- [ ] … impossible to represent in a UML diagram.
23+
- [ ] … achieved using the `;` (semicolon) symbol.
24+
- [ ] … a way of connecting a *basic* class with a *derived* class.
25+
26+
<details><summary>Comment</summary>
27+
The class inherited from is called the *base*, superclass or parent class, but not *basic*.
28+
</details>
29+
1930
#. Suppose your are given an `ElectricDevice` class and a `WallDecor` class. You would like to write a `Clock` class that represents at the same time an electric device and a wall decor. This is possible only if the `ElectricDevice` and `WallDecor` classes are…
2031

2132
- [ ] Sealed
@@ -38,6 +49,26 @@ tags:
3849

3950
## Problems
4051

52+
#. Assume given the following class implementation:
53+
54+
```
55+
!include code/projects/Computer/Computer/Computer.cs
56+
```
57+
58+
Write a `Laptop` class that
59+
60+
#. Inherits from `Computer`,
61+
#. Has one single (automatic) property, called `ScreenSize`, of type `int`,
62+
#. Has a constructor that takes 2 parameters of appropriate datatypes, and use them to set `brand` and `ScreenSize`,
63+
#. Has a `ToString` method that returns a `string` containing the brand and screen size.
64+
65+
66+
<details><summary>Solution</summary>
67+
```{download="code/projects/Computer.zip"}
68+
!include code/projects/Computer/Computer/Laptop.cs
69+
```
70+
</details>
71+
4172
#. Consider the diagram representing the "Room", "ClassRoom", "Office" classes and their relations.
4273

4374
!include diag/cla/RoomClassroomOffice.md

0 commit comments

Comments
 (0)