Access the full text.
Sign up today, get DeepDyve free for 14 days.
CHAPTER 6 ■ ■ ■ As discussed in Chapter 1, it makes sense to derive one class from another if the derived class is an example of the base class. The Engineer Class The following class implements Engineer and methods to handle billing for Engineer: using System; class Engineer // constructor public Engineer(string name, float billingRate) this.name = name; this.billingRate = billingRate; // figure out the charge based on engineer's rate public float CalculateCharge(float hours) return(hours * billingRate); // return the name of this type public string TypeName() return("Engineer"); private string name; protected float billingRate; 39 40 CH APTER 6 ■ BASE CLA SSES AND INHERITA NC E class Test public static void Main() Engineer engineer = new Engineer("Hank", 21.20F); Console.WriteLine("Name is: {0}", engineer.TypeName()); Engineer will serve as a base class for this scenario. It contains the private field name and the protected field billingRate. The protected modifier grants the same access as private; however, classes that are derived from this class also have access to the field. Protected is therefore used to give classes that derive from this class access to a field. Protected access allows other classes to depend upon the internal implementation of the class and
Published: Jan 1, 2005
Keywords: Base Class; Correct Function; Abstract Function; Abstract Class; Real Type
Read and print from thousands of top scholarly journals.
Already have an account? Log in
Bookmark this article. You can see your Bookmarks on your DeepDyve Library.
To save an article, log in first, or sign up for a DeepDyve account if you don’t already have one.
Copy and paste the desired citation format or use the link below to download a file formatted for EndNote
Access the full text.
Sign up today, get DeepDyve free for 14 days.
All DeepDyve websites use cookies to improve your online experience. They were placed on your computer when you launched this website. You can change your cookie settings through your browser.