• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object class without any constructor!  RSS feed

 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!
In java-docs sun is showing default constructor for Object class where as in source code it's not seen. In fact object must have a default constructor which will get called when you create instance for any class.
Then why it is not shown in source code(for Object) of J2sdk1.4???


-Sachin!!!
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that is the default constructor.

If no constructor is explicitly defined, then one is automatically added that accepts no arguments and sets all member variables to null, 0, false, ect.
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very true!!! But if they are showning it in docs means it must be there in src code(physicaly).


-Sachin!!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sachin Dimble:
But if they are showning it in docs means it must be there in src code(physicaly).

No, that's not true. A constructor does not need to be in the source code explicitly for javadoc to generate documentation for it.

Try it yourself; write a class without any constructors (so that the compiler automatically generates the no-args constructor) and run javadoc on the source file. You'll see that the generated documentation mentions the constructor, even though it's not in your source code.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that java.lang.Object is a special case.
The default constructor is not there - after all, all constructors directly or indirectly contain a call to super(...) - see a problem?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Morris:
Note that java.lang.Object is a special case.
The default constructor is not there - after all, all constructors directly or indirectly contain a call to super(...) - see a problem?


If Object does not have a default constructor, what do the constructors of direct subclasses call. Surely it would be more logical that the Object constructor is a special case that doesn't contain a call to super().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!