• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of Default constructor ?  RSS feed

 
Roshi Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of default constructor provided by compiler ?

Is it only to provide default values to class instance variable which is done by compiler ?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. There's a rule that every class must have a constructor. So if you don't provide one, the compiler will provide one for you.
 
Roshi Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:No. There's a rule that every class must have a constructor. So if you don't provide one, the compiler will provide one for you.


ya that's my question ... what it does ??

Does a default constructor provided by compiler do anything ?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It, um, constructs the instance of the class, when invoked with thenew keyword.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roshi Kumar wrote:Does a default constructor provided by compiler do anything ?

If you mean: does it contain any code? Answer: No.

Winston

[Edit] Well, except for a call to "super()", that is.
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Default constructor may look innocuous but it becomes very handy in several scenarios. For eg. in a library, like
Hibernate, if an instance is to be made then it makes use of default constructor.

Manish
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!