Results 1 to 9 of 9
- 03-22-2011, 10:21 AM #1
Member
- Join Date
- Mar 2011
- Location
- Nagpur
- Posts
- 2
- Rep Power
- 0
- 03-22-2011, 10:30 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
- 03-22-2011, 10:36 AM #3
Member
- Join Date
- Mar 2011
- Location
- Nagpur
- Posts
- 2
- Rep Power
- 0
sir i want only explanation not a link
- 03-22-2011, 10:47 AM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102
- Rep Power
- 0
the reason is very well described in that link.
- 03-22-2011, 10:49 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Java doesn't have multiple inheritance (MI) of implementation; it does have MI of type (interface). MI of implementation is a burden because it needs carefull fiddling with the 'this' pointer and Java tries to keep things simple so it doesn't implement it. If a class D already extends a class B and you also want to 'extend' it a class C, class C needs to implement an interface CI, so you have:
Now create an instance of C and pass it to D as follows:Java Code:interface CI { void aMethod(); } class C implements CI { ... } class D extends B { ... }
As you can see a B passed the call to aMethod() to its member c and it implements CI, just as a C does. Through composition you have the same effect as if MI of implementation were allowed.Java Code:class D extends B implements CI { private C c; public D(C c) { this.c= c; } public void aMethod() { c.aMethod(); } }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-22-2011, 10:55 AM #6
There is a way of Multiple inheritances in Java using Interfaces
One reason why multiple class inheritance in not allowed because class describe HOW to do a thing and in interface describes only WHAT to do that's why it is allowed at interface level only
because in case of class, a subclass can not decide which implementation to picksanjeev,संजीव
- 03-22-2011, 11:10 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Say you subclassed two different classes, and both classes have a method of the same name, how would the compiler be able to tell the difference?
This is one of the things that makes multiple inheritance more difficult. In the end it comes down to the fact that using single inheritance is easier.
- 03-22-2011, 11:27 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
C++ can't tell the difference either, it picks the implementation that is first in the list of extended classes, i.e.
if a method M would've been present in both B1 and B2, the implementation of M in B1 is chosen because B1 comes first in the list.Java Code:class C : B1, B2 { ... }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-22-2011, 11:29 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
How to put multiple image in java?
By Miwrath in forum New To JavaReplies: 5Last Post: 10-12-2010, 11:38 AM -
Running multiple threads on multiple CPU cores?
By Dosta in forum Threads and SynchronizationReplies: 2Last Post: 09-19-2010, 03:48 PM -
Multiple Java in a single BOX
By luke_devon in forum New To JavaReplies: 2Last Post: 07-05-2010, 01:59 PM -
multiple inheritance in java
By pawanspace in forum New To JavaReplies: 2Last Post: 12-31-2007, 04:08 AM -
Multiple Inheritance in java
By paty in forum New To JavaReplies: 4Last Post: 08-02-2007, 02:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks