C++

   1 #include <iostream>
   2 #include <string>
   3 using namespace std;
   4 
   5 class Message {
   6 private:
   7    string txt;
   8 public:
   9    Message(string s){ txt = s;}
  10    void Print() const { cout << txt;}
  11 };
  12 
  13 int main()
  14 { 
  15    Message M("Hello world");
  16    M.Print();
  17 }

Delphi

program hellopas;
{$APPTYPE CONSOLE}
uses windows;

type Message = class
        txt : string;
        constructor create(s:string);
        procedure print;
end;

constructor Message.Create(s:string);
begin
        txt := s
end;
procedure Message.print;
begin
        writeln(txt)
end;

var m : Message;

begin
        m := Message.Create('Hello world');
        m.print()
end.
ch3n2k.com | Copyright (c) 2004-2020 czk.