• Post Reply Bookmark Topic Watch Topic
  • New Topic

an interface can extend more than one interface in java  RSS feed

 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I was just going through and got one doubt...
Can anybody tell me "Why only an interface can extend more than one interface in java and why not same thing is implemented for Class,Why special previlages for interface only ?
James
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a class extends more than one class, then if several of these superclasses implement a method with the same signature, then when you call the same method on the subclass, it's ambiguous which method should be called. You need a set of surprisingly complicated rules to choose which should be called. For C++, it took years to figure out what the rules should be, and then even more years until there were compiler implementations that correctly followed the rules. When Java was first released (1994,) conforming C++ compilers still didn't exist! So Java avoids the whole issue.
The problem doesn't come up for interfaces since interfaces don't have method implementations. If you inherit the same signature from two interfaces, well, OK, that still means you have to implement one method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!