• Post Reply Bookmark Topic Watch Topic
  • New Topic

every java class inherits object?  RSS feed

 
Deena Raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that multiple inheritence is not allowed in java. But every clas inherits the object class by default, if my class extends another class is it not extending two classes? For example:
Class A extends B{
}
Now class A extends Object by default too. SO isnt it multiple inheritence?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.

multiple inheritance refers to a class having two (or more) PARENT classes.

Your class A has one parent, B. B has one parent, which could be C. you can work your way up the chain, eventually getting to the Object class.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not what multiple inheritance means. It means extending the "top" class, which in Java is called java.lang.Object (not plain Object) by two routes. Actually Java does support multiple inheritance, but only in interfaces.


Prohibited:-Permitted, but not called multiple inheritance:-Permitted:-But that only works because interfaces have only empty methods, and no actual functionality to extend.

never create a class called Object yourself unless you want to get completely confused.
[ April 20, 2007: Message edited by: Campbell Ritchie ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!