Results 1 to 3 of 3
  1. #1
    mallikanala is offline Member
    Join Date
    Jun 2011
    Posts
    10
    Rep Power
    0

    Thumbs down servlet interface

    In core java i observe for interfaces we not able to create object.
    But in servlet i saw for interfaces we can able create object.

    example:

    ServletContext context=null;
    and more ......
    why tel me the reasn pls.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default

    Java Code:
    ServletContext context=null;
    This creates a reference to the data type: ServletContext and gives it a null value. It does NOT create an object.
    Later in the program you can assign to that variable any reference to a class that implements the ServletContext interface.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    See What Is an Interface? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)
    In the example you provided (SevletContext), you are not creating an object of said interface, you have a reference to an object that implements the interface.

Similar Threads

  1. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 05:06 PM
  2. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  3. Replies: 0
    Last Post: 08-30-2008, 12:52 PM
  4. Replies: 1
    Last Post: 08-07-2007, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •