You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stated differently, an object in `Class2`*is a(n object in)*`Class1`, but the converse is not true: an object in `Class1`*is not* an object in `Class2`.
45
45
46
+
47
+
In addition, observe that the `Class2` constructor *cannot* access `class1`'s `attribute1` directly, since it is marked as `private`: it needs to use the `SetAttribute1` method.
48
+
46
49
## Polymorphism and References
47
50
48
51
Note that a `Class1` object can be created using a `Class2` constructor, since an object in `Class2`*is a(n object in)*`Class1`.
49
52
Formally, we can write:
50
53
51
54
```
52
-
Class1 object3 = new Class2();
55
+
Class1 test = new Class2("property1", "property2", "attribute1");
53
56
```
54
57
55
-
and then manipulate `object3` like any other *object from `Class1` (it is, in a way, "truncated").
58
+
and then manipulate `test` like any other *object from `Class1` (it is, in a way, "truncated").
56
59
In particular, we can use
57
60
58
61
```
59
-
object3.Property1 = "Test";
62
+
test.Property1 = "Test";
60
63
```
61
64
62
-
but `object3.Property2 = "Test";` would not compile *since we would be trying to access a property of `Class2` with a `Class1` object.*
63
-
Remember that an object in `Class1`*is not* an object in `Class2`, and that the way we declared it, `object3`*is* a `Class1` object.
65
+
but `test.Property2 = "Test";` would not compile *since we would be trying to access a property of `Class2` with a `Class1` object.*
66
+
Remember that an object in `Class1`*is not* an object in `Class2`, and that the way we declared it, `test`*is* a `Class1` object.
64
67
65
68
## Solving Ambiguity by Overriding
66
69
67
70
### For Methods
68
71
69
72
Now, consider the following class implementation and usage:
0 commit comments