Skip to content

Commit 3a91ac8

Browse files
committed
Merge branch 'main' of github.com:princomp/princomp.github.io
2 parents cc34db9 + 9a44c44 commit 3a91ac8

7 files changed

Lines changed: 34 additions & 0 deletions

File tree

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

source/solutions/oop/inheritance.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ tags:
3434
- [ ] Protected
3535
- [ ] Constructors
3636

37+
#. An abstract class…
38+
39+
- [ ] … can be instantiated.
40+
- [x] … can contain a constructor.
41+
- [x] … can contain abstract and non-abstract methods.
42+
- [x] … is represented in a UML diagram by prefixing its name with \<\<Abstract\>\>.
43+
44+
#. In a UML diagram, an abstract method is …
45+
46+
- [ ] … underlined.
47+
- [ ] … impossible to distinguish from a non-abstract method.
48+
- [x] … necessarily part of an abstract class.
49+
- [x] … in italics.
50+
51+
#. A class `Student` inheriting from an abstract class `Person`
52+
53+
- [ ] … must override all of `Person`'s methods.
54+
- [x] … must implement all the methods marked `abstract` in `Student`.
55+
- [x] … can be instantiated.
56+
- [x] … is connected to `Person` using an open triangle end and a continuous line (⇽) on the UML diagram.
57+
- [ ] … is connected to `Person` using an open triangle end and a dashed line (◁┈) on the UML diagram.
58+
3759
#. A method with header `public virtual void Test(int a, out int b)` will…
3860

3961
- [ ] Return a value
@@ -47,6 +69,18 @@ tags:
4769
- [x] Need to be inside an `abstract` class
4870
- [x] Not be overriden
4971

72+
#. Give at least two differences between an abstract class and an interface.
73+
74+
<details><summary>Solution</summary>
75+
A possible list includes:
76+
77+
- An abstract class can contain `private` methods.
78+
- An abstract class is *inherited* by another class, while an interface is *realized* by another class.
79+
- An class can inherit from only one abstract class, but it can realize multiple interfaces.
80+
- Interfaces do not need to explicitly mark their methods and properties as public or abstract, since they are always public and abstract.
81+
- Abstract methods in an abstract class need to be explicitly overridden by methods in the class inheriting from them, while classes realizing interfaces need not to mark the methods as explicitely overriding methods from the interface.
82+
</details>
83+
5084
## Problems
5185

5286
#. Assume given the following class implementation:

0 commit comments

Comments
 (0)