• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Object Class is father of all??

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not multiple inheritance as you cannot create a class that does NOT extend java.lang.Object.

Nick
 
lowercase baba
Posts: 13074
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
expectation is the root of all heartache - shakespeare. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic