Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>extends</code> is for <em>extending</em> a class.</p> <p><code>implements</code> is for <em>implementing</em> an interface</p> <p>The difference between an interface and a regular class is that in an interface you can not implement any of the declared methods. Only the class that "implements" the interface can implement the methods. The C++ equivalent of an interface would be an abstract class (not EXACTLY the same but pretty much).</p> <p>Also java doesn't support <strong>multiple inheritance</strong> for classes. This is solved by using multiple interfaces.</p> <pre><code> public interface ExampleInterface { public void doAction(); public String doThis(int number); } public class sub implements ExampleInterface { public void doAction() { //specify what must happen } public String doThis(int number) { //specfiy what must happen } } </code></pre> <p>now extending a class</p> <pre><code> public class SuperClass { public int getNb() { //specify what must happen return 1; } public int getNb2() { //specify what must happen return 2; } } public class SubClass extends SuperClass { //you can override the implementation @Override public int getNb2() { return 3; } } </code></pre> <p>in this case</p> <pre><code> Subclass s = new SubClass(); s.getNb(); //returns 1 s.getNb2(); //returns 3 SuperClass sup = new SuperClass(); sup.getNb(); //returns 1 sup.getNb2(); //returns 2 </code></pre> <p>I suggest you do some more research on <strong>dynamic binding, polymorphism and in general inheritance in Object-oriented programming</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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