 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
vaibhav Guest
|
Posted: Sun May 13, 2007 1:34 am Post subject: Inheritance question???Object class |
|
|
hi all,
im basically a newbie to java
java doesnt support multiple inheritance
ie you can atmost extend only from one class
and implement other interfaces to simulate mulitple inheritance
as far as i have read by default every class extends the Object class
<-
ie
class abc == class abc extends Object
now since every class has already extended from it how can it extend
from other classes from my point of view
if java has only single inheritance this should not be possible
and since it is possible there should be a way out if not then how is
this achieved???
regards
vaibhav.y.netkar |
|
| Back to top |
|
 |
Eric Sosman Guest
|
Posted: Sun May 13, 2007 2:06 am Post subject: Re: Inheritance question???Object class |
|
|
vaibhav wrote:
| Quote: | hi all,
im basically a newbie to java
java doesnt support multiple inheritance
ie you can atmost extend only from one class
and implement other interfaces to simulate mulitple inheritance
as far as i have read by default every class extends the Object class
-
ie
class abc == class abc extends Object
now since every class has already extended from it how can it extend
from other classes from my point of view
if java has only single inheritance this should not be possible
|
class ABC extends Object
class DEF extends ABC
class GHI extends DEF
class JKL extends GHI
...
| Quote: | and since it is possible there should be a way out if not then how is
this achieved???
|
You have only one mother, and she has only one mother,
and she in turn has only one mother; that's single inheritance.
Even though you are directly descended from only one of them,
you are "transitively descended" from them all.
To put it less fancifully: Consider drawing a graph of all
Java classes in a JVM, with arrows from each class to the class
it extends. From any class, there is an oriented path leading
(eventually) to Object. Single inheritance means that the path
is unique, that the graph is a tree with Object as its root.
--
Eric Sosman
esosman@acm-dot-org.invalid |
|
| Back to top |
|
 |
Richard Reynolds Guest
|
Posted: Sun May 13, 2007 2:07 am Post subject: Re: Inheritance question???Object class |
|
|
"vaibhav" <vaibhav.netkar (AT) gmail (DOT) com> wrote in message
news:1179002056.961054.54030 (AT) e51g2000hsg (DOT) googlegroups.com...
| Quote: | hi all,
im basically a newbie to java
java doesnt support multiple inheritance
ie you can atmost extend only from one class
and implement other interfaces to simulate mulitple inheritance
as far as i have read by default every class extends the Object class
-
ie
class abc == class abc extends Object
now since every class has already extended from it how can it extend
from other classes from my point of view
if java has only single inheritance this should not be possible
and since it is possible there should be a way out if not then how is
this achieved???
regards
vaibhav.y.netkar
but that isn't multiple inheritance, since every class implicitly extends |
Object, Object is the "root" of your single inheritance tree e.g.
you write a class with no "extends" clause:
Object->YourClass
you now write a class that extends YourClass:
Object->YourClass->YourNewClass
that's still single inheritance. |
|
| Back to top |
|
 |
Lew Guest
|
Posted: Sun May 13, 2007 9:40 pm Post subject: Re: Inheritance question???Object class |
|
|
"vaibhav" <vaibhav.netkar (AT) gmail (DOT) com> wrote
| Quote: | as far as i have read by default every class extends the Object class
|
The key words are "by default". That does not mean "always". It completely
negates the "every". It is only by default that a class extends Object. It
certainly does not have to.
The actual rule is, "Every class extends exactly one other class, except
Object, which extends no other class."
The English first-person singular pronoun "I" is always capitalized (or
capitalised, depending on which dialect of English you write).
--
Lew |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|