MCC - CIS161AD
CS9ex Classes - Programming Example
   cs.gif

CS9ex is a very simple example to demonstrate inheritance. The driver program has been modified to include the testing of the derived class. Students should referred to the class definition when completing their CS9 assignment. Students are NOT required to create and submit this project, but students may download and expand the self-extracting CS9ex Inheritance archive into their own workspace if they like.

CS9ex Sample Form:

Interface (cs9ex_interface.jpg)

Method Redefinition:
In clsEmployeeUnion, setUnionDues is a redefined method. The redefined method will be used when the object is declared as clsEmployeeUnion. The definition found in the base class clsEmployee will be used when the object is declared as clsEmployee. To allow redefintion, the method must be declared as virtual in the base class, and the key word override is used in the derived class.

setUnionDues of base class clsEmployee:

using System;
using System.Collections.Generic;
using System.Text;

//Juan Marquez - clsEmployee used to calculate gross and net pay

namespace CS9ex
{
    class clsEmployee
    {
       . . .

        //define as virtual so definition can be overriden in derived class
        public virtual void setUnionDues()
        {
            cdecUnionDues = cdecUNION_MEMBER_NO;
        }

       . . .


    }//end of class
}//end of namespace

clsEmployeeUnion Definition:
using System;
using System.Collections.Generic;
using System.Text;

//Juan Marquez - clsEmployeeUnion used to process Union Members

namespace CS9ex
{
    class clsEmployeeUnion : clsEmployee 
    {
       private const decimal cdecUNION_MEMBER_YES = 10.00M;

        public clsEmployeeUnion()
            : base()
        {
            // default constructor
        }

        public clsEmployeeUnion(string strName, int intHours, decimal decRate)
            : base(strName, intHours, decRate)
        {
            //Overloaded constructor
            //call base-class constructor and pass the values
        }

        //override definition of virtual definition in base
        public override void setUnionDues()
        {
            cdecUnionDues = cdecUNION_MEMBER_YES;
        }
    }//end of class
}// end of namespace


Revised: 03/22/2011 - www.mesacc.edu/~marquez/cis162ad/cs9ex_inheritance.html