Author |
Message |
Okapi
|
Posted: Wed Nov 12, 2008 8:31 pm Post subject: Multiple Inheritance |
|
|
Is there anyway to use multiple inheritance with abstract classes?
Simple example:
abstract class Pet(){
//abstract methods
}
abstract class Dog extends Pet{
}
abstract class Cat extends Pet{
}
Is there anyway a class CatDog (freak of nature) extend both Cat and Dog? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Vermette
![](http://compsci.ca/v3/uploads/user_avatars/637825944810b5d4444c6.jpg)
|
Posted: Wed Nov 12, 2008 9:53 pm Post subject: Re: Multiple Inheritance |
|
|
Java by design does not support multiple inheritance. There is a lot of argument as to whether this is a good or bad thing (most say bad), but sticking to a strict hierarchy design was done to avoid some types of design problems that can creep in.
To capture common behaviour between classes you can define an Interface.
edit: http://en.wikipedia.org/wiki/Interface_(Java) |
|
|
|
|
![](images/spacer.gif) |
pavol
|
Posted: Wed Nov 12, 2008 9:57 pm Post subject: RE:Multiple Inheritance |
|
|
I'm not sure if there is any way to do that, but the way I would solve the problem is to try and put the Dog and Cat classes together into one so you don't have to extend both. I guess what I'm saying is if you are going to use Dog and Cat to just try to make CatDog, then make CatDog only and you won't have to extend anything except for Pet.
Is this the problem you were having? with the Dog and Cat classes or was it just an example and you were curious if you can extend two classes? |
|
|
|
|
![](images/spacer.gif) |
Vermette
![](http://compsci.ca/v3/uploads/user_avatars/637825944810b5d4444c6.jpg)
|
|
|
|
![](images/spacer.gif) |
|