Results 1 to 4 of 4

Thread: Actual use of interface in java other than multiple inheritance

  1. #1
    Join Date
    Jan 2009
    Posts
    97

    Actual use of interface in java other than multiple inheritance

    Hi All,

    I am IT student, I have lots confusion regarding java interfaces.

    What is the actual use of interface in java apart other than multiple inheritance?

    I don't have idea about why sun-java included the interface concept.

    Can anybody of you provide information regarding use of interfaces?

    Please help me in this...

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Actual use of interface in java other than multiple inheritance

    The one of essential use of the interface is to relate classes from different types of hierarchy.

    See the below example:

    for this example, lets take 2 classes:

    public abstract class Vegetable {
    }
    public class Tomato extends Vegetable {
    }
    public abstract class Car {
    }
    public class Mercedes extends Car {
    }
    There is no common content between above classes.

    but above two classes might be washed. so you are able to declare an interface 'washable'.

    public interface Washable {
    void wash();
    }

    then implement this in the two abstract classes.
    now, suppose if you have a program with both Car objects and vegetable objects, and you have to wash them, you can use:



    List<Washable> objectsToWash = new Arraylist<Washable>();
    for(Washable washableObject: objetsToWash){
    washableObject.wash();
    }


    Above may help you in your problem.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Actual use of interface in java other than multiple inheritance

    Hi,

    For you kind information in java multiple inheritance is not available.
    But in most cases multiple inheritance plays the important role,that's why they introduced interface as a subsidiary for multiple inheritance.

    Class and interfaces are similar in nature. But the only difference is that you can't create anything within interfaces, And also we can not create instances for them.

    I hope this details is able to solve you confusion....

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Actual use of interface in java other than multiple inheritance

    Hi guys,

    I am not expert in the java programming. But this is you understanding that we can implement Multiple Inheritance in java programming.

    The main use of interface is to implement the abstract class. We are not able to create anything in interface.

    This is all which I know..

Similar Threads

  1. how to use multiple inheritance in core java
    By Mewad in forum Software Development
    Replies: 4
    Last Post: 08-01-2011, 10:31 AM
  2. Problem with inheritance in java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 12:10 PM
  3. What does Inheritance mean in java?
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 11:45 AM
  4. How to achieve multiple inheritance in C sharp?
    By Rum in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 08:51 AM
  5. Multiple Inheritance in Java
    By KALINDA in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 07:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,626,669.95952 seconds with 16 queries