title: Getters Setters with user input
body: <p>Is using getters and setters with userinput a good practice? I looked for some example but was not able to find any. While the code below works but is this a good practice?  I noticed If I use the code below I am not able to use constructor.   Thank You for your explanation.</p>
  
  <pre><code>public class Tests{
  
      private String name;
      private int id;
  
      Scanner userinput = new Scanner(System.in);
  
      public void setName(){
          System.out.println("Enter a name: ");
          name= userinput.next();     
      }
  
      public String getName(){
  
          return name;
      }
  
      public void displayInfo(){
          setName();
          System.out.println("You entered " + this.getName());
      }
      public static void main(String [] args){
  
          Tests test = new Tests();
          test.displayInfo();
  
      }
  
  }
  </code></pre>