Free since 2005 · No login required
AT

Academic Tutorials

Learn at your own pace

site-mobile-top-banner · 320x50

Pascal Does Not Support Object Oriented Programming

Added 31 Jul 2008

Initially designed and released by Apple Computer in 1986, Object Pascal was developed as an extension to Pascal to support object-oriented programming. Object support is incorporated in THINK Pascal, CodeWarrior Pascal, Borland Pascal and various open source Pascals. As an example, the following code illustrates Object Pascal under the Codewarrior Pascal dialect (see Figure 8 below).

Program OOP_Sample;

Type
Employee = object
firstName: string;
lastName: string;
hourlyWage: real;
Function Pay(hoursWorked: integer): real;
end;
ExemptEmployee = object(Employee)
Function Pay(hoursWorked: integer): real; override;
end;

Var
anyEmp: Employee;
exEmp: ExemptEmployee;

Function Employee.Pay(hoursWorked: integer): real;

begin (* Pay with deduction for benefits *)
Pay := hourlyWage * hoursWorked - 100;
end;

Function ExemptEmployee.Pay(hoursWorked: integer): real;

begin (* Pay with no deductions *)
Pay := hourlyWage * hoursWorked;
end;

begin
new(exEmp);
exEmp.Hire('John','Smith',15);
writeln('As exempt, pay ',exEmp.lastName,' $',exEmp.pay(40):8:2);
new(anyEmp);
anyEmp.Hire('Jane','Doe',15);
writeln('As a regular employee, pay ', anyEmp.lastName,
' $', anyEmp.pay(40):8);
end.