title: how to print instance variable in methods in java?
body: <p>I am trying to print the variable in show() method. But in every time it is showing default value like for string NULL and for integer 0. I took a parameterize constructor. As I need to pass the argument at the time of creating an object of the class instead of that I want to pass any variable which will carry the value of that variable from the user, but I am not able to perform.</p>
  <pre><code>import java.util.*;
  
  public class Cons_With_Arg {
      String s;
      int i;
      // Scanner sc=new Scanner(System.in);
  
      Cons_With_Arg(String name, int id) {
          Scanner sc = new Scanner(System.in);
          this.s = name;
          System.out.print(&quot;enter Name:&quot;);
          name = sc.nextLine();
          this.i = id;
          System.out.print(&quot;enter id:&quot;);
          id = sc.nextInt();
      }
  
      public void show() {
          System.out.println(&quot;Name:&quot; + this.s);
          System.out.println(&quot;Id:&quot; + this.i);
      }
  
      public static void main(String[] args) {
          Cons_With_Arg co = new Cons_With_Arg(s, i);
          // System.out.println(&quot;Name:&quot; + co.s);
          // System.out.println(&quot;Id:&quot; + co.i);
          co.show();
      }
  }
  </code></pre>