Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-01-2011
Member
 
Join Date: Dec 2010
Posts: 87
how to use multiple inheritance in core java

I?m a beginner in programming and I want to know about core java. How can we use multiple inheritance in core java. I know c++ but about java I?m not sure that we can use or not. Please tell me, is it possible to use multiple inheritance in core java. If yes, than how ?. please tell me about this and give me the code from which I can understand the program. Please explain me the concept of multiple inheritance.
Reply With Quote
  #2  
Old 05-01-2011
Member
 
Join Date: Apr 2009
Posts: 567
Re: how to use multiple inheritance in core java

Yes, you can use multiple inheritance in core java but not directly. You can not use multiple inheritance in a way which we are using in c++. The concept of multiple inheritance is different in core java. You can use multiple inheritance through interface in core java. In c++ we extending classes for multiple inheritance and in core java we implements a interface because class does not support in core java for multiple inheritance.
Reply With Quote
  #3  
Old 05-01-2011
Member
 
Join Date: May 2009
Posts: 525
Re: how to use multiple inheritance in core java

Class does not support multiple inheritance in java. We can say it?s a disadvantage or reusability. Using multiple inheritance through classes have some disadvantagethat is why a new concept of interface is introduce. For example consider class A as superclass class B and C are sub class of A.comment : class cannot extend more than one class think class D extends B and the method present in a class A B C are different if u call a method in class than we don?t know which method we are calling either A or B or c.
Let?s take a example:
Take two classes say class A and class B

class A
{
doSomething()
{
//the fun code goes here...
}
}

class B
{
doSomething()
{
//serious code goes here
}
}

class C extends A extends B // let's assume for a minute Java permitted Multiple Inheritence
{

doSomething(); //which method will it call? the method present in A or B?

}
Reply With Quote
  #4  
Old 05-01-2011
Member
 
Join Date: May 2009
Posts: 533
Re: how to use multiple inheritance in core java

Actually java has solved the problem which we are facing in c++. In c++ there is a big problem of ambiguity in multiple inheritance but in java we use interface to define a function so that no ambiguity should occur. Java is a vast but implements simplicity to avoiding ambiguity of methods and variables in multiple inheritance it also save memory. If you want a code of multiple inheritance using interface than you can search on internet for source code.
Reply With Quote
  #5  
Old 08-01-2011
Member
 
Join Date: May 2008
Posts: 1,020
Re: how to use multiple inheritance in core java

Java does not support multiple interface java was designed without multiple inheritance, but it support indirectly through interface. One of the reason why java is not supporting multiple inheritance directly is ?ambiguity?. If java allows multiple inheritance like in c++ than Jvm (java virtual machine ) doesn?t understand which method is to be call. Jvm will get confuse. So to avoid confusion and ambiguity java introduce a new concept called ?interface?.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "how to use multiple inheritance in core java"
Thread Thread Starter Forum Replies Last Post
What does Inheritance mean in java? Mithun Seth Software Development 5 08-02-2010 11:45 AM
How to achieve multiple inheritance in C sharp? Rum Software Development 5 19-01-2010 08:51 AM
Various forms of inheritance in java Jabeen Software Development 3 20-11-2009 09:03 AM
Actual use of interface in java other than multiple inheritance Saaz Software Development 3 19-11-2009 09:24 AM
Multiple Inheritance in Java KALINDA Software Development 3 03-11-2009 07:43 PM


All times are GMT +5.5. The time now is 10:23 AM.