Chapter 9 discussed access modifiers public, private, and internal. A class's public members are accessible wherever the application has a reference to an object of that class or one of its derived classes. A class's private members are accessible only within the class itself. A base class's private members are inherited by its derived classes, but are not directly accessible by derived class methods and properties. In this section, we introduce access modifier protected. Using protected access offers an intermediate level of access between public and private. A base class's protected members can be accessed by members of that base class and by members of its derived classes. (Members of a class can also be declared protected internal. A base class's protected internal members can be accessed by members of that base class, by members of its derived classes and by any class in the same assembly.)
All non-private base class members retain their original access modifier when they become members of the derived class (i.e., public members of the base class become public members of the derived class, and protected members of the base class become protected members of the derived class).
Derived class methods can refer to public and protected members inherited from the base class simply by using the member names. When a derived class method overrides a base class method, the base class version of the method can be accessed from the derived class by preceding the base class method name with the keyword base and the dot (.) operator. We discuss accessing overridden members of the base class in Section 10.4.
|
Relationship between Base Classes and Derived Classes |
Preface
Index
Introduction to Computers, the Internet and Visual C#
Introduction to the Visual C# 2005 Express Edition IDE
Introduction to C# Applications
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Methods: A Deeper Look
Arrays
Classes and Objects: A Deeper Look
Object-Oriented Programming: Inheritance
Polymorphism, Interfaces & Operator Overloading
Exception Handling
Graphical User Interface Concepts: Part 1
Graphical User Interface Concepts: Part 2
Multithreading
Strings, Characters and Regular Expressions
Graphics and Multimedia
Files and Streams
Extensible Markup Language (XML)
Database, SQL and ADO.NET
ASP.NET 2.0, Web Forms and Web Controls
Web Services
Networking: Streams-Based Sockets and Datagrams
Searching and Sorting
Data Structures
Generics
Collections
Appendix A. Operator Precedence Chart
Appendix B. Number Systems
Appendix C. Using the Visual Studio 2005 Debugger
Appendix D. ASCII Character Set
Appendix E. Unicode®
Appendix F. Introduction to XHTML: Part 1
Appendix G. Introduction to XHTML: Part 2
Appendix H. HTML/XHTML Special Characters
Appendix I. HTML/XHTML Colors
Appendix J. ATM Case Study Code
Appendix K. UML 2: Additional Diagram Types
Appendix L. Simple Types
Index