 <p>You can use:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>private float x; public float X { get { return x; } }</code></pre> </div> </div> </p> <p>Now you only set x from within your class.</p>