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
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Notice that while we can't use `name` from outside of `Person`, we can still use it from within an instance method of `Employee` because `Employee` derives from `Person`.
191
191
192
+
A constructor may also be marked `protected`.
193
+
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,
return`Hello, my name is ${this.name} and I work in ${this.department}.`;
212
+
}
213
+
}
214
+
215
+
let howard =newEmployee("Howard", "Sales");
216
+
let john =newPerson("John"); // Error: The 'Person' constructor is protected
217
+
```
218
+
192
219
## Parameter properties
193
220
194
-
In our last example, we had to declare a private member `name` and a constructor parameter `theName`, and we then immediately set `name` to `theName`.
221
+
In our last example, we had to declare a protected member `name` and a constructor parameter `theName` in the `Person` class, and we then immediately set `name` to `theName`.
195
222
This turns out to be a very common practice.
196
223
*Parameter properties* let you create and initialize a member in one place.
197
224
Here's a further revision of the previous `Animal` class using a parameter property:
0 commit comments