title: Java Servlets Overriding init(ServletConfig config)
body: <p>I am trying to override init(ServletConfig config) method.My code is:</p>
  
  <pre><code> public void init(ServletConfig config) throws ServletException {
      ServletContext sc = getServletContext(); // ----- NullPointerException
  }
  </code></pre>
  
  <p>this is giving NullPointerException .</p>
  
  <p>If i modify it as:</p>
  
  <pre><code>   public void init(ServletConfig config) throws ServletException {
      ServletContext sc = config.getServletContext(); // ----- works fine
  }
  </code></pre>
  
  <p>This works fine.
   I know that we should override init() method and not init(ServletConfig config) but<br>
   Can anybody give me proper reason as why this is happening?</p>