ASP.NET 2.0 All-In-One Desk Reference For Dummies®
by Doug Lowe, Jeff Cogswell, Ken Cox - Microsoft MVP
Chapter 6. Working with Inheritance
In This Chapter
✓ | Explaining inheritance |
✓ | Creating derived classes |
✓ | Using protected access |
✓ | Demystifying polymorphism |
You probably already know that a C# class can be based on another class. When that happens, the class becomes like a child to the parent class: It inherits all the characteristics of the parent class, good and bad. All the fields, properties, and methods of the parent class are passed on to the child class. The child class can use these members as is, or it can override them to provide its own versions. In addition, the child class can add fields, properties, or methods of its own.
Inheritance is considered by some to be an advanced topic of object-oriented programming, but it’s a topic that can’t be ignored when you work in ASP.NET because every ASP.NET page you create inherits a .NET Framework class called System.Web.UI.Page. To write even a trivial program, you need to understand the implications of this fact.
Understanding Inheritance
The word inheritance conjures up several different non-computer meanings:
Children inherit certain characteristics from the parents. For example, two of my three children have red hair. Hopefully, they won’t be half bald by the time they’re 30.
Children can also inherit behavior from their parents. As they say, the apple doesn’t fall far from the tree.
When someone dies, their heirs get their stuff. Some of it is good stuff, but some of it may not be. My kids are going to have a great time rummaging through ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access