title: Printing object variable of Java inbuilt class vs Printing object of my class
body: <p>In my Java project, I have a class called <code>myInteger</code> with the following code:</p>
  <pre><code>    public class myInteger {
  
           private int data;
  
           public myInteger(int data) {
                this.data = data;
           }
      }
  </code></pre>
  <p>Now I have another class called <code>MainClass</code> which contains the main method. I am creating two objects: First object of the <code>java.lang.Integer</code> class and the second object of <code>myInteger</code> class. Then, I print both the object variables by passing the <code>integer</code> and <code>myInteger</code> to the <code>println</code> method.</p>
  <pre><code>    public class MainClass {
  
             public static void main(String[] args) {
                 Integer integer = new Integer(1);
                 myInteger myInteger = new myInteger(1);
                 System.out.println(integer);
                 System.out.println(myInteger);
             }
      }
  </code></pre>
  <p>I get the following output:</p>
  <blockquote>
  <p>1</p>
  <p>MainClass.myInteger@67ea6afc</p>
  </blockquote>
  <p>In the case of <code>Integer</code> class, I get the auto-unboxed integer value. But in the second case, I get reference.</p>
  <p>Why does this happen? Is there any way to print <code>data</code> field of myInteger object without using any sort of <code>getter</code> methods?</p>