File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In what case i will not be able to implement multiple inheritance by interfaces?

 
Soumya Ranjan Padhi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true that in java for multiple inheritance we use Interfaces. But are there any special programming scenarios that restricts us while implementing multiple inheritance through interfaces?
 
Winston Gutkowski
Bartender
Pie
Posts: 9501
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Soumya Ranjan Padhi wrote:It is true that in java for multiple inheritance we use Interfaces. But are there any special programming scenarios that restricts us while implementing multiple inheritance through interfaces?

Don't quite understand the question, but the only "restriction" I can think of is implementing two or more interfaces with overlapping methods, where they don't all have the same meaning.

And before you ask me if I can provide an example, please SearchFirst (←click). Alternatively, read the tutorials.

Winston
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot implement multiple inheritance in Java (or C#), whether you implement multiple interfaces or not. Methods implemented from an interface have to be written anew in their implementing classes, so you are really only mimicking multiple inheritance.
Collisions are problems, as Winston said, where
  • 1: Several methods have the same signature but different return types: won’t compile, or,
  • 2: Several methods in different interfaces have different intentions: design incompatibility.
  • If you look at these three methods, you will see their documentation has been very carefully written to avoid such incompatibilities: 1 2 3.
     
    Winston Gutkowski
    Bartender
    Pie
    Posts: 9501
    50
    Eclipse IDE Hibernate Ubuntu
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:You cannot implement multiple inheritance in Java (or C#), whether you implement multiple interfaces or not.

    Hmmm, I agree with the sentence because of the word "implement", but you can certainly effect multiple type inheritance.

    Like most things, it should be used in moderation though.

    Winston
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic