Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why we have an Abstract Interface  RSS feed

 
Balachandar Nayak
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

What is the purpose of having an interface and its methods defined as being abstract? To me, this is completely redundant:

abstract interface sampleInt {
public abstract display();
}
If it's an interface, of course you have to implement its definition - which is what being abstract means. What is the point of basically specifying the same thing twice?




Regards
Bala
 
joseph huang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to do with polymorphism. You know that toy you had as a kid where you pull the string and depending on what animal it pointed to, it made the sound of the animal? So instead of calling each animal and asking it to moo, bark, meow, or quack, you could just call the same method, say, makesound(), and it would behave according to its own implementation. You could do that for a lot of other behaviors too, like print, display, etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!