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

program Loomad1;

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

  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: TLoom;
     minuKass: TKass;
     minuKoer: TKoer;

begin
  minuKass := TKass.luua ('Kiti');
  minuKoer := TKoer.luuaNimeta;
  minuLoom := TLoom.luuaNimeta;
  minuLoom.paneNimi ('Patu'); 
  writeln (minuKass.toString);
  writeln (minuKoer.toString);
  writeln (minuLoom.toString);
  minuLoom.vabastada;
  minuLoom := minuKoer;
  writeln (minuLoom.toString);
  minuLoom := minuKass;
  writeln (minuLoom.toString);
  minuKass := TKass (minuLoom);
  writeln (minuKass.toString);
  minuKass.vabastada;
  minuKoer.vabastada;
end.

