title: Can C++'s class variables be initialized without a constructor like in Java?
body: <p>In Java I could create a class and initialize a variable without a constructor:</p>
  
  <pre><code>public class Foo {
  private int x = 1;
  public getx() {
      return x;
      }
  }
  </code></pre>
  
  <p>But in c++, to accomplish the same thing, the only way I know how is to do this:</p>
  
  <pre><code>class Foo
  {
  private:
      int x;
  public:
      Foo()
      {
          x = 1;
      }
      getx()
      {
          return x;
      }
  };
  </code></pre>