• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object Class is father of all??

 
Monarch Bhojani
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all
if object class is the base of all classes then the classes we create extending another classes may also extend Object class
Is this not multiple inheritance

Please reply
Regards
Monarch
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not multiple inheritance as you cannot create a class that does NOT extend java.lang.Object.

Nick
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If every Chihuahua extends Dog, and every Dog extends Mammal, would you call this multiple inheritance, since Chihuahuas extend both Dog and Mammal?

It's the same with Object. Every class either DIRECTLY extends Object, unless you declare it to extend something else. But that OTHER class then extends from Object... or from a class that extends Object... or antoher class...

You can trace a direct path up from any class to Object, but each class only had one immediate 'parent' class.
 
Jeff Jetton
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All good responses. Just to clarify, the fact that classes can inherit from classes that, themselves, inherit from another class is not considered "multiple inheritance". Each class has one, and only one, parent, even though it can have a "grandparent", a "great-grandparent", and so on.

So, what is the definition of multiple inheritance? It's when a class can inherit directly from two or more classes at the same time. In other words, it has multiple "parents". You'd be able to write somthing like this:

class Mule extends Horse, Donkey
{

}

Of course, Java doesn't let you do that. You must use interfaces in order to do something similar (but not exactly) like it. Other languages, most notably C++, do let you acheive true multiple inheritance.

- Jeff
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be implementing multiple inheritance if your hierarchy looks like a directed, acyclic graph (DAG) as opposed to a tree.
 
Raj Young
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java supports multiple inheritance with respect to interface but not to implmentation.

So Java's support to multiple inheritance limits with interface, not to implementaion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic