-4

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?

Qadeer Hussain
  • 653
  • 2
  • 7
  • 17
  • Google is your best friend. For example, this article give an example of when you would want to use an interface: http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html – SF Lee May 04 '14 at 11:33
  • The most obvious use is to define that 2 otherwise separate classes can both behave similarly in a single situation. For example the interface `Scannable` might be implemented by both buildings and people in a game because both can be scanned. The Scanner class doesn't care what something is, only that it implements `Scannable` – Richard Tingle May 04 '14 at 11:39

1 Answers1

0

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.

Community
  • 1
  • 1
flitbit
  • 168
  • 1
  • 2
  • 9