• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface extending another interface.Why do we need it?  RSS feed

 
Shyam kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a known thing that an interface can extend another interface in java. But why do we need to do it in the first place, can anyone give me a scenario or a reason to do it? Please make me undustand this. I cannot find the benefit of doing it?
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For exactly the same reason you would want to extend a normal class.

Let's say you have an interface exposing the methods you can call on a Vehicle object. You can then define a Car interface which extends the Vehicle interface. Every Class which implements the Car interface would then have to implement the methods from the Car interface as well as the Vehicle interface.

You would have to use interfaces (or maybe abstract classes) for the above example as you can not create a Vehicle or a Car (it is not specific enough).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!