aspose file tools*
The moose likes Beginning Java and the fly likes Creating an object from an interface (like ServletConfig) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating an object from an interface (like ServletConfig)" Watch "Creating an object from an interface (like ServletConfig)" New topic
Author

Creating an object from an interface (like ServletConfig)

Deepak Giri
Ranch Hand

Joined: Feb 12, 2009
Posts: 52
sorry, might be the question is too silly but still can't help without asking (the reason might be that my mind has become completely useless at this point)

we know in the life cycle of a servlet, in the early stages, an object of ServletConfig is passed to the init() method (which is called by the container).
but i'm wondering how can we create an object of an interface (which ServletConfig is)???


SCJP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

Moved to Java in General (with appropriate change of title).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

Deepak Giri wrote:how can we create an object of an interface (which ServletConfig is)???

You don't. You create an object of a (concrete) class that implements the interface.

In the specific case of ServletConfig, the container (Tomcat, for example) instatiates a class that implementes ServeltConfig. We don't know which class that is, and more importantly we don't care!
Deepak Giri
Ranch Hand

Joined: Feb 12, 2009
Posts: 52
thanks

by the way, can you tell me the exact signature of that init(ServletConfig) method?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

It's in the JavaDoc.
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Here is the link to the Java API Collection.

You need to check the Enterprise Edition API
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creating an object from an interface (like ServletConfig)