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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top