Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Question Regarding Interfaces

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question Regarding Interfaces

    I have a question.
    how do interface perform some task without having body in java. For example
    RequestDispatcher rd=request.getRequestDispatcher(“Login.html”);
    rd.include(request, response);

    My doubt is include method is not implemented. so how it is performing its tasks?????
    I am new to java


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Question Regarding Interfaces

    The actual object held by rd is not a direct RequestDispatcher instance, but rather another class which implements the RequestDispatcher interface. As such it must provide an implementation of all the methods RequestDispatcher requires. This is a guarantee enforced by the compiler.

    You can get the actual object type held:

    System.out.println(rd.getClass().getName());

    Note that the code won't always output something easily decipherable or make sense (particularly when dealing with nested/anonymous classes), but it will return what implementing class object is being held.

Similar Threads

  1. Interfaces
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 14
    Last Post: July 13th, 2018, 12:57 AM
  2. marker interfaces
    By anupam0021 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 20th, 2011, 06:53 PM
  3. Interfaces
    By leyland in forum Java Theory & Questions
    Replies: 4
    Last Post: April 5th, 2011, 08:51 PM
  4. Can't understand why Interfaces are there
    By vortexnl in forum Object Oriented Programming
    Replies: 9
    Last Post: February 14th, 2011, 01:06 PM
  5. Importance of interfaces
    By jyothishey in forum Object Oriented Programming
    Replies: 9
    Last Post: March 12th, 2010, 07:11 AM