title: Accessing implemented class methods through interface reference without constructor initialization
body: <p>I have a class <code>CommonDaoImpl</code> that implements an interface <code>CommonDao</code>. Now i am trying to access the <code>getRegisterData()</code> of <code>CommonDaoImpl</code> through interface <code>CommonDao</code> reference like this</p>
  
  <pre><code>public class CommonServiceImpl implements CommonService 
  {
      CommonDao commonDao
      public boolean insertRegisterData(CommonBean objCommonBean)  {
          return commonDao.getRegisterData(objCommonBean);
      }
  </code></pre>
  
  <p>but it is not working and thow an NullPointerException</p>
  
  <p>So i slightly change my code and initialize interface reference with the constructor of implemented class CommonDao impl like this</p>
  
  <pre><code>public class CommonServiceImpl implements CommonService 
  {
      CommonDao commonDao=new CommonDaoImpl();
  
      public boolean getRegisterData(CommonBean objCommonBean)  {
          return commonDao.insertRegisterData(objCommonBean);
      }
  </code></pre>
  
  <p>But i could not understand why it happens.</p>