
(* transleerimisel FreePascalis kasutage võtit -Sd  *)

program Loomad;

  type
    TLoom =
      object
         fNimi: string;
         constructor luuaNimeta;
         constructor luua (n: string);
         destructor vabastada;
         function votaNimi: string;
         procedure paneNimi (n: string);
         function toString: string; virtual;
      end;
    TKoer =
      object (TLoom)
         fSabaga: Boolean;
         constructor luuaNimeta;
         constructor luua (n: string);
      end;
    TKass =
      object (TLoom)
         fVurruPikkus: integer;
         function toString: string; virtual;
      end;

    Loom = ^TLoom;
    Koer = ^TKoer;
    Kass = ^TKass;

  constructor TLoom.luuaNimeta;
    begin
      fNimi := 'nimetu';
    end;

  constructor TLoom.luua (n: string);
    begin
      fNimi := n;
    end;

  constructor TKoer.luuaNimeta;
    begin
      fSabaga := true;
      inherited luuaNimeta;
    end;

  constructor TKoer.luua (n: string);
    begin
      fSabaga := true;
      inherited luua (n);
    end;

  destructor TLoom.vabastada;
    begin
      writeln ('Vabastati ' + fNimi);
    end;

  procedure TLoom.paneNimi (n: string);
    begin
      fNimi := n; 
    end;

  function TLoom.votaNimi: string;
    begin
      votaNimi := fNimi; 
    end;

  function TLoom.toString: string;
    begin
      toString := 'Olen loom ' + votaNimi;
    end;

  function TKass.toString: string; 
    var s: string;
    begin
      s := inherited toString;
      toString := s + ' ja seejuures KASS';
    end;

  var minuLoom: Loom;
     minuKass: Kass;
     minuKoer: Koer;

begin
  minuKass := new (Kass, luua ('Kiti'));
  minuKoer := new (Koer, luuaNimeta);
  minuLoom := new (Loom, luuaNimeta);
  minuLoom^.paneNimi ('Patu'); 
  writeln (minuKass^.toString);
  writeln (minuKoer^.toString);
  writeln (minuLoom^.toString);
  dispose (minuLoom, vabastada);
  minuLoom := minuKoer;
  writeln (minuLoom^.toString);
  minuLoom := minuKass;
  writeln (minuLoom^.toString);
  minuKass := Kass (minuLoom);
  writeln (minuKass^.toString);
  dispose (minuKass, vabastada);
  dispose (minuKoer, vabastada);
end.

