aspose file tools*
The moose likes Java in General and the fly likes In what case i will not be able to implement multiple inheritance by interfaces? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "In what case i will not be able to implement multiple inheritance by interfaces?" Watch "In what case i will not be able to implement multiple inheritance by interfaces?" New topic
Author

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

Soumya Ranjan Padhi
Greenhorn

Joined: Jun 27, 2012
Posts: 10
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

Joined: Mar 17, 2011
Posts: 7063
    
  16

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


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

    Joined: Mar 17, 2011
    Posts: 7063
        
      16

    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
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: In what case i will not be able to implement multiple inheritance by interfaces?
     
    Similar Threads
    Difference Between Abstract Class and Interface
    Multiple Inheritance - Reusability
    Abstract & Interface
    innerclass
    multiple inheritance in java