+ 3
Does java really support multiple inheritance ?
Its very well known that java does not support class based multiple inheritance but using interface that can be achieved. But main advantage of inheritance is re usability and in case of multiple inheritance based on inheritance the concrete class which will implement the child interface will have to give the implementation of all the methods defined in parents interface. So we are not able to to achieve what inheritance is there for. So does java really support multiple inheritance.
4 Antworten
+ 2
Java doesn't support multiple inheritance it only support single inheritance. You can use aggregation with Java it works like multiple inheritance.
+ 1
There is no support for multiple inheritance in java.
The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick.
That's why Interface comes in picture.
For more details please refer http://javapapers.com/core-java/why-multiple-inheritance-is-not-supported-in-java/
0
@Sarafaraz: I too know all this but my question is some thing different. please read carefully and then only answer
- 1
Using Interface we can achieve multiple inheritable. An interface can implement another interface and a class can implement as many interface as required.
Here is the example. The class "Test" is implementing both interface Printable and Showable.
interface Printable
{
void print();
}
interface Showable
{
void show();
}
class Test implements Printable,Showable
{
public void print()
{
System.out.println("Hello");
}
public void show()
{
System.out.println("Welcome");
}
public static void main(String args[])
{
Test obj = new Test();
obj.print();
obj.show();
}
}
Output will be:
Hello
Welcome