Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does the constructor of object class looks like ?  RSS feed

 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to ask that how the constructor of object class looks like ,for instance I have a no-argument constructor in my class which does nothing so it will call super() implicitly so it will be calling constructor of object class so then how are the instance variables initialized ?Basically I want to see how the constructor of object class works .
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Object class' constructor doesn't do anything. Object doesn't have fields to initialize.
 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then how are the instance variables of the class which we create are initialized ?It is the role of constructor only to initialize the instance members of the class so then if object class constructor does nothing so then why is it called by the compiler using super() ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably because it's more difficult to write a compiler that makes an exception for the Object class, than it is to write one that follows a consistent rule that applies to all classes.
 
Paul Clapham
Sheriff
Posts: 22528
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides, somebody might write an implementation of Java in which the Object class does have a private variable which needs to be initialized for some reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!