• Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple inheritance  RSS feed

 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we know that for all classes Object is the superclass..

assume that i am writing a super class and a subclass..

eg;
class A
{}
class B extends A
{}

so class B also has extended Object right?? doenst it mean that it is multiple inheritance???
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not multiple inheritance, as you can only directly extend one class.
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


is this not an implicit multiple inheritance.??? ok by doing extends we cant do that... but is this case not an exceptional one??? if you could explain me little more i will be thankful to u..
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vignesh hariharan:

is this not an implicit multiple inheritance.???


"Multiple inheritance" refers to a tree-like inheritance structure. A straight-line inheritance hierarchy, in which each class extends only one other class, is called "single inheritance." If you want to invent a term and call it "implicit multiple inheritance" instead, you can certainly go ahead and do that, although no one will understand what you mean!

As long as we're making up names for things, I think I will call integers "degenerate floating point values." Like it?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
99.9% (approx) of programmers agree on what the term "multiple inheritance" means vs. what "single inheritance" means.

single means each class only directly extends one class. yes, the heirachy can go up pretty high, but ultimatly each class has at most ONE direct parent, and at most one grandparent, etc.

multiple inheritance means that a class DIRECTLY extends TWO OR MORE. in C++ you can say (not sure of the exact syntax)

class myClass extends mother, father, cousinIt

so here, you'd get everything from all three classes. this is not allowed in java.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

At least that is how I think of it. If I am wrong please correct me.

In Java it could be said that every class(except Object) has exactly one parent. This is not the case in other languages that support OOP(like C++)
[ June 05, 2006: Message edited by: Rusty Shackleford ]
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vignesh hariharan:
we know that for all classes Object is the superclass..

assume that i am writing a super class and a subclass..

eg;
class A
{}
class B extends A
{}

so class B also has extended Object right?? doenst it mean that it is multiple inheritance???


The "multiple" or "single" adjective on inheritance refers to the number of immediate baseclasses a class has. It does not not refer to the total number of base classes.

In your example, I would answer, "No, B does NOT extend Object -- B only extends A."

Let's add some code:



B inherits equals() and hashcode() from A only, not from A and Object. B also inherits toString() from A, not from Object. Of course A inherits toString() from Object, so it's like B inherited it from Object directly.
[ June 05, 2006: Message edited by: Ryan McGuire ]
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you people... i got confused with single inheritance and multiple inheritance.. thanks a ton..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!