Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

in simple servlet ,why a constructor has super()?.

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in simple servlet ,why a constructor has super()?.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because, Servlet must need to have default constructor[no-arg constructor]. Container use the default constructor to instantiate the servlet .
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,then what the super() keyword does???

in some scenariop init method also contains super() ,then what it does here??
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:
in some scenariop init method also contains super() ,then what it does here??


Wrong . init() method doesnt have super() . super() calls the super class default constructor . compilar put the super() at the first statement of the constructor implicitly. you cant call super() from methods . but you can call super class method from your sub class method using super.methodSuper(). so you probably saw the super.init(config); from
public void init(ServletConfig config)

Hope This Helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic