Forums Register Login

every java class inherits object?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 913 times.
Similar Threads
Java Inheritance
Does JAVA support multiple inheritance or not
how every java program extends Object class by default
java inheritance
Multiple Inheritence in JAVA
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:12:45.