demand. For this purpose, the Base Class Library

Public Class CExecutive Inherits CEmployee ‘ Calculate salary increase based on 5% car allowance as well Overrides Sub IncSalary(ByVal sngPercent As Single) Me.Salary = Me.Salary * CDec(1.05 + sngPercent) End Sub End Class There are two things to note here. First, the line: Inherits CEmployee indicates that the CExecutive class inherits the members of the CEmployee class. Put another way, an object of type CExecutive is also an object of type CEmployee. Thus, if we define an object of type CExecutive: Dim ceo As New CExecutive then we can invoke the Salary property, as in: ceo.Salary = 1000000 Second, the keyword Overrides in the IncSalary method means that the implementation of IncSalary in CExecutive is called instead of the implementation in CEmployee. Thus, the code: ceo.IncSalary raises the salary of the CExecutive object ceo based on a car allowance. Note also the presence of the Overridable keyword in the definition of IncSalary in the CEmployee class, which specifies that the class inheriting from a base class is allowed to override the method of the base class. Next, we define the CSecretary class, which also inherits from CEmployee but implements a different salary increase for secretary objects: ‘ Secretary Class Public Class CSecretary Inherits CEmployee ‘ Secretaries get a 2% overtime allowance Overrides Sub IncSalary(ByVal sngPercent As Single) Me.Salary = Me.Salary * CDec(1.02 + sngPercent) End Sub End Class We can now write code to exercise these classes: ‘ Define new objects Dim ThePresident As New CExecutive( ) Dim MySecretary As New CSecretary( ) ‘ Set the salaries ThePresident.Salary = 1000000 MySecretary.Salary = 30000 ‘ Set Employee to President and inc salary Debug.Writeline(”Pres before: ” & CStr(ThePresident.Salary)) ThePresident.IncSalary(0.4) Debug.WriteLine(”Pres after: ” & CStr(ThePresident.Salary))

Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Virtualwebstudio j2ee web hosting services

Comments are closed.