Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy to use Interfaces, Multiple Inheritance vs Interfaces, Benefits of Interfaces?
    primarykey
    data
    text
    <p>I still have some confusion about this thing. What I have found till now is </p> <p>(Similar questions have already been asked here but I was having some other points.)</p> <blockquote> <ol> <li><p>Interface is collection of ONLY abstract methods and final fields.</p></li> <li><p>There is no multiple inheritance in Java.</p></li> <li><p>Interfaces can be used to achieve multiple inheritance in Java.</p></li> <li><p>One Strong point of Inheritance is that We can use the code of base class in derived class without writing it again. May be this is the most important thing for inheritance to be there.</p></li> </ol> </blockquote> <p>Now..</p> <blockquote> <p>Q1. As interfaces are having only abstract methods (no code) so how can we say that if we are implementing any interface then it is inheritance ? We are not using its code.</p> <p>Q2. If implementing an interface is not inheritance then How interfaces are used to achieve multiple inheritance ?</p> <p>Q3. Anyhow what is the benefit of using Interfaces ? They are not having any code. We need to write code again and again in all classes we implement it. </p> </blockquote> <p><strong>Then why to make interfaces ?</strong></p> <p><strong>NOTE :</strong> I have found one case in which interfaces are helpful. One example of it is like in Runnable interface we have public void run() method in which we define functionality of thread and there is built in coding that this method will be run as a separate thread. So we just need to code what to do in thread, Rest is pre-defined. But this thing also can be achieved using abstract classes and all. </p> <p><strong>Then what are the exact benefits of using interfaces? Is it really Multiple-Inheritance that we achieve using Interfaces?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload