Sometimes, you only want certain methods accessible from your child objects. Protected is one of the ways you can do that.
- [Instructor] Protected's probably the more confusing … of the access modifiers, just because it has a couple … of moving parts, unlike private and public, … which are pretty straightforward. … Protected has to do with having essentially … a private modifier that allows you to use a value … in a parent and sibling class. … It also causes some issues with implements. … So if you remember earlier, implements means we're actually … just matching the shape of the object … while extends is actually a child of our parent class. … Now, let's say protected was on age here. … You'll notice that there's no way for us to actually … implement Animal now because of the protected property. … In order for this to match it, it needs to be a child. … If we were to get rid of this, you'll see we still … have this issue because age is missing in type Dog. … But if we have it there, the property is protected … and thus it's not a derived class of Animal. … So when you're using protected, you're not going to be able …
Skill Level Intermediate
TypeScript: Upgrades and Featureswith Emmanuel Henri1h 15m Advanced
TypeScript for Node.js Developerswith Emmanuel Henri1h 2m Intermediate
1. Classes in TypeScript
2. Inheritance in TypeScript
3. Access Modifiers in TypeScript
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.