title: Which variables constructor can access in Java class?
body: <p>I am studying constructors in Java (OOP) but couldn't figure it out that what type of variables constructor can access? Which of the following variables could be accessed by constructor?</p>
  
  <ol>
  <li>a local variable defined by any method</li>
  <li>a private instance variable</li>
  <li>a public instance variable</li>
  <li>a static variable</li>
  </ol>
  
  <p>I created following example to elaborate my question:</p>
  
  <pre><code>public class constructorAccess {
      public int marks; // 3. Public instance variable
      private String firstName; // 2. Private instance variable
      static final String LASTNAME = "Smith"; // 4. Static variable
  
      public static void studentId(){
          int id; // 1. Local variable inside method
          id = 5;
          System.out.println(id);
      }
  
      public constructorAccess(int marks, String firstName) {
          this.marks = marks;
          this.firstName = firstName;
      }
  }
  </code></pre>
  
  <p>Is it possible to access <code>id</code>(1. Local variable declared in the studentId method) and <code>LASTNAME</code> (4. static variable declared in the class) from constructorAccess?</p>
  
  <pre><code>public constructorAccess(int marks, String firstName) {
     this.marks = marks;
     this.firstName = firstName;
     // How can I use id variable here from studentId method?
     // How can I use LASTNAME static variable here?
  }
  </code></pre>
  
  <p>I accessed the private and public instance variables with this. to reference but the <code>LASTNAME</code> and <code>id</code> variables give me error (create a local variable).</p>