my dog learned polymorphism*
The moose likes Servlets and the fly likes in simple servlet ,why a constructor has super()?. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "in simple servlet ,why a constructor has super()?." Watch "in simple servlet ,why a constructor has super()?." New topic
Author

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

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
in simple servlet ,why a constructor has super()?.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Because, Servlet must need to have default constructor[no-arg constructor]. Container use the default constructor to instantiate the servlet .
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
ok,then what the super() keyword does???

in some scenariop init method also contains super() ,then what it does here??
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
 
 
subject: in simple servlet ,why a constructor has super()?.
 
Similar Threads
Use of constructor in abstract class?
Do constructors are really not inheited???
Using super and this in the constructor together
initialization sequence - what is done first?
Constructors and Polymorphism