|
34 | 34 | - [ ] Protected |
35 | 35 | - [ ] Constructors |
36 | 36 |
|
| 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 | + |
37 | 59 | #. A method with header `public virtual void Test(int a, out int b)` will… |
38 | 60 |
|
39 | 61 | - [ ] Return a value |
|
47 | 69 | - [x] Need to be inside an `abstract` class |
48 | 70 | - [x] Not be overriden |
49 | 71 |
|
| 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 | + |
50 | 84 | ## Problems |
51 | 85 |
|
52 | 86 | #. Assume given the following class implementation: |
|
0 commit comments