Ejemplo de una classe

pascal:
                                   
program Virtual_2;

uses crt;
{$R+}

type
   Vehicle = object
      Wheels : integer;
      Weight : real;
      constructor Init(In_Wheels : integer; In_Weight : real);
      procedure Message; virtual;
   end;


   Car = object(Vehicle)
      Passenger_Load : integer;
      constructor Init(In_Wheels : integer;
                       In_Weight : real;
                       People    : integer);
      procedure Message; virtual;
   end;


   Truck = Object(Vehicle)
      Passenger_Load : integer;
      Payload        : real;
      constructor Init(People : integer;
                       Max_Load : real;
                       In_Wheels : integer;
                       In_Weight : real);
      procedure Message; virtual;
   end;

{ ********************* Implementacion ******************** }

   constructor Vehicle.Init(In_Wheels : integer; In_Weight : real);
   begin
      Wheels := In_Wheels;
      Weight := In_Weight;
   end;

   procedure Vehicle.Message;
   begin
      WriteLn('This message is from the vehicle.');
   end;



   constructor Car.Init(In_Wheels : integer;
                        In_Weight : real;
                        People    : integer);
   begin
      Wheels := In_Wheels;
      Weight := In_Weight;
      Passenger_Load := People;
   end;

   procedure Car.Message;
   begin
      WriteLn('This message is from the car.');
   end;



   constructor Truck.Init(People : integer;
                          Max_Load : real;
                          In_Wheels : integer;
                          In_Weight : real);
   begin
      Passenger_Load := People;
      Payload := Max_Load;
      Wheels := In_Wheels;
      Weight := In_Weight;
   end;

   procedure Truck.Message;
   begin
      WriteLn('This message is from the truck.');
   end;



   procedure Output_A_Message(VAR Machine : Vehicle);
   begin
      Write('This is from Output_A_message; ');
      Machine.Message;
   end;


{ ************************ main program ************************** }

var Unicycle : Vehicle;
    Sedan    : Car;
    Semi     : Truck;

begin

   Unicycle.Init(1, 12.0);
   Sedan.Init(4, 2100.0, 5);
   Semi.Init(1, 25000.0, 18, 5000.0);

   WriteLn;
   Unicycle.Message;
   Sedan.Message;
   Semi.Message;

   WriteLn;
   Output_A_Message(Unicycle);
   Output_A_Message(Sedan);
   Output_A_Message(Semi);
   readkey;
end.




{ Result of execution

This message is from the vehicle.
This message is from the car.
This message is from the truck.

This is from Output_A_Message; This message is from the vehicle.
This is from Output_A_Message; This message is from the car.
This is from Output_A_Message; This message is from the truck.

}
¿Ya le viste algún error? Dejanos tu correción ;-)

Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress elimina los tags HTML. Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios.

Otro punto antes de comentar, Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:

De esta manera el código sale coloreado.

Otro punto importante para muchos que sienten que se les ignora: Todos los comentarios los reviso y en su debido momento los apruebo, pero ojo con el último párrafo.

Para poner los símbolos de las librerías sin que desaparezcan, debes escribir los símbolos de mayor > y menor qué < con su entidad HTML correspondiente, así como el símbolo de &

Mis Algoritmos se reserva el derecho de alterar, publicar o no los comentarios así como cambiar estas reglas de uso.

Si estas de acuerdo, adelante puedes comentar :)

P.D. No le hago tareas a nadie, mejor hagan la mía :P