title: Hi...Shouldn't the id_public variable give the result as 81 & 86? Why is it taking up different memory locations for both the derive classes?
body: <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  class Parent {
      public:
      int id_public;
  };
  
  class Child1 : public Parent {
      public:
      void setId(int id) {
          id_public = id;
          cout&lt;&lt;id_public&lt;&lt;endl;
      }
  };
  
  class Child2 : public Parent {
      public:
      void setId2(int id) {
          cout&lt;&lt;id_public&lt;&lt;endl;
          id_public += id;
          cout&lt;&lt;id_public&lt;&lt;endl;
      }
  };
  
  int main() {
      Child1 obj1;
      Child2 obj2;
  
      obj1.setId(81);
      obj2.setId2(5);
  
      return 0;
  }
  </code></pre>