Class extending more than one class Java?
No it is not possible in java (Maybe in java 8 it will be avilable). Except the case when you extend in a tree. For example:
class A
class B extends A
class C extends B
In Java multiple inheritance is not permitted. It was excluded from the language as a design decision, primarily to avoid circular dependencies.
Scenario1: As you have learned the following is not possible in Java:
public class Dog extends Animal, Canine{
}
Scenario 2: However the following is possible:
public class Canine extends Animal{
}
public class Dog extends Canine{
}
The difference in these two approaches is that in the second approach there is a clearly defined parent or super
class, while in the first approach the super
class is ambiguous.
Consider if both Animal
and Canine
had a method drink()
. Under the first scenario which parent method would be called if we called Dog.drink()
? Under the second scenario, we know calling Dog.drink()
would call the Canine
classes drink
method as long as Dog
had not overridden it.