wood burning stoves 2.0*
The moose likes Java in General and the fly likes Multiple Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple Inheritance" Watch "Multiple Inheritance" New topic
Author

Multiple Inheritance

tarun saha
Greenhorn

Joined: Mar 23, 2010
Posts: 27
hi guys,

I have read many docs regarding multiple inheritance in java.

I know that in java one class can extend only one class but can implement many interfaces, but still my doubt remains unclear.

If i have 3 classes

public class MyClassA{
}

public class MyClassB{
}

public class MyClassC{
}

how can inherit the properties of the 3 classes. I read that multiple interfaces can be implemented. But interface cannot extend a class. So how will interface use the properties of class?

Lets say that my main intented class is

public class AllClassProperties which will have certain selected properties same as the three( i am not saying common properties, it is only selected properties and their methods)

how can i bridge between AllClassProperties and the three myclasses?

CAN WE USE INTERFACE INSIDE A CLASS?

please help me with a complete example or a link if you can...

thanks for any help in advance.
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
You could create interfaces for each of those classes (InterfaceA for MyClassA etc.), and have



Eclipse has support for delegation (Source -> Generate Delegate Methods).

If you search for composition inheritance, you'll find many articles, e.g.
http://www.artima.com/lejava/articles/designprinciples4.html
tarun saha
Greenhorn

Joined: Mar 23, 2010
Posts: 27
hmm, i'l try it out.
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
tarun saha wrote:hmm, i'l try it out.


In general, try not to create classes that are overcomplicated. Implementing several interfaces will bring lots of public functions; the delegate methods will mean lots of code (even though generated). Check whether you can simplify the design, whether there's no way to avoid this class taking on so much functionality/responsibility.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance