File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Interface Implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Interface Implementation" Watch "Interface Implementation" New topic
Author

Interface Implementation

Mike Mann
Greenhorn

Joined: Nov 21, 2003
Posts: 4
I am having a hard time with interfaces.
I know that if a Class Implements the interface it must provide concrete methods that the Interface uses, but here is my problem.
Class HttpServlet Implements Servlet, Servlet Config and Serializable.
Yet in most of it's methods it uses a reference to an HttpServlet.
The HttpServlet is an Interface but it is not implemented.
How is this allowed?
I see alot of the Classes in Java doing this, and I am having a hard time understanding how.
Thanks Mike Mann
Mike Mann
Greenhorn

Joined: Nov 21, 2003
Posts: 4
Need to Clarify my last.It uses an HttpServletRequest Interface as an Reference.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

If there exists a class

then a variable of type HttpServletRequest can legally refer to a SomeClass object; a SomeClass is an HttpServletRequest. Therefore, if a method takes an HttpServletRequest as a parameter, that means that to call it, you would have to pass an instance of an object that implements that interface.
This is really the whole point of interfaces; they let you specify what a class should look like, and make use of an instance of that class, without naming the actual class.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Interface Implementation
 
Similar Threads
HttpServlet API
init missing in servlet
Question related to Abstract class HttpServlet
HttpServlet
Basic Servlet Doubt