└── 16_Inheritance_Kalitim └── Inheritance.pas /16_Inheritance_Kalitim/Inheritance.pas: -------------------------------------------------------------------------------- 1 | program Project1; 2 | 3 | {$APPTYPE CONSOLE} 4 | {$R *.res} 5 | 6 | uses 7 | System.SysUtils; 8 | 9 | type 10 | TPerson = class(TObject) 11 | FirstName: string; 12 | LastName: string; 13 | function FullName: string; virtual; 14 | end; 15 | 16 | TEmployee = class(TPerson) 17 | EmployeeID: integer; 18 | Salary: double; 19 | function CalculateYearlySalary: double; 20 | function FullName: string; override; 21 | end; 22 | 23 | { TPerson } 24 | 25 | function TPerson.FullName: string; 26 | begin 27 | Result := FirstName + ' ' + LastName; 28 | end; 29 | 30 | var 31 | Person: TPerson; 32 | Employee: TEmployee; 33 | 34 | { TEmployee } 35 | 36 | function TEmployee.CalculateYearlySalary: double; 37 | begin 38 | Result := Salary * 12; 39 | end; 40 | 41 | function TEmployee.FullName: string; 42 | begin 43 | Result := 'Employee is ' + inherited FullName; 44 | end; 45 | 46 | begin 47 | 48 | Person := TPerson.Create; 49 | try 50 | Person.FirstName := 'Abdullah'; 51 | Person.LastName := 'ILGAZ'; 52 | WriteLn('Your name is ' + Person.FullName); 53 | finally 54 | Person.Free; 55 | end; 56 | 57 | Employee := TEmployee.Create; 58 | try 59 | Employee.FirstName := 'Michael'; 60 | Employee.LastName := 'Jordan'; 61 | Employee.EmployeeID := 23; 62 | Employee.Salary := 10000; 63 | WriteLn(Employee.FullName + '. Employee ID is ' + Employee.EmployeeID.ToString); 64 | finally 65 | Employee.Free; 66 | end; 67 | 68 | ReadLn; 69 | 70 | end. 71 | --------------------------------------------------------------------------------