title: Print 3 Objects from the same class
body: <p>I started to read a book and at some point I came to <code>class</code> and after I created my first class and created in <code>main</code> an object, I decided to create two more Object on the same class. The program works fine but the Output seems to be different from my Understanding.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Data{
      public:
          Data( string z ){
              cout &lt;&lt; z &lt;&lt; endl;
          }
          void setName ( string x ){
              name = x;
          }
  
          string getName( void ){
              return name;
          }
      private:
          string name;
  };
  
  int main ( void ){
      Data obj1( "Hello" );
      Data obj2( "World" );
      Data obj3( "!" );
  
      cout &lt;&lt; obj3.getName() &lt;&lt; endl;
      cout &lt;&lt; obj2.getName() &lt;&lt; endl;
      cout &lt;&lt; obj1.getName() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>And here is the Output:</p>
  
  <pre><code>Hello
  World
  !
  </code></pre>
  
  <p>But I thought it will print this:</p>
  
  <pre><code>!
  World
  Hello
  </code></pre>
  
  <p>Why does that happen?</p>