Frage

suppose in case of class like

class  person
  {
     String name;
    public void setName()
     {
     }

      }
  class labor extends Person
      {
      }

in that case sub class can reuse the base class data member and function but in the case of interfaces

 interface person
  {

     public void setName();


  }
   class labor extends Person
      {
       }

here we have to give the implementation of a function then if we must have to give the implementation of a function than what is the benifit of a interfaces because if we have to give the definition then without interface we can write a new function in a class and do every thing?

War es hilfreich?

Lösung

Interfaces declare what behavior and characteristics an object will have when implemented. They are explicitly abstract, which is why you still need to define actual implementations on your objects later.

A fairly classic example and description was provided in the answer to this question.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top