• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface Implementation  RSS feed

 
Mike Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need to Clarify my last.It uses an HttpServletRequest Interface as an Reference.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!