• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?






 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic