• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this a Default Constructor or if not then What is it?  RSS feed

 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

In the StudentDriver class is the line StudentDriver(){} the default constructor? If it is then why did I need to actually write out the code line ? I thought default constructors were given automatically?






 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Austin wrote:
In the StudentDriver class is the line StudentDriver(){} the default constructor? If it is then why did I need to actually write out the code line ? I thought default constructors were given automatically?


Default no-arg constructors are automatically created if the class does not have any constructors defined. In this case, there is another constructor defined.

Henry
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Lisa Austin wrote:
In the StudentDriver class is the line StudentDriver(){} the default constructor? If it is then why did I need to actually write out the code line ? I thought default constructors were given automatically?


Default no-arg constructors are automatically created if the class does not have any constructors defined. In this case, there is another constructor defined.

Henry


Oh! I remember that now. Thank You Henry!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you create it explicitly, it's no longer called a default constructor (because it's no longer defaulted), but a nullary constructor.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And when you create it explicitly, it's no longer called a default constructor (because it's no longer defaulted), but a nullary constructor.


Ah gotcha! Thanks Bear! Nice to see a fellow Austinite BTW Thank You so much.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!