• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Which statement is true for default Constructor?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is true?



K&B1.4 page 334 has the following statement.

1) The default constructor is a no-arg constructor with a no-arg call to super().

2) Instance methods and variables are only accessible after the super constructor runs.
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
both are true.
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
default constructor = no-parameter constructor.

subclasses with "default constructor" will call (compile-time check) "default constructor" of its superclass.

I believe initialisation happens when we create instances, when we call "new".
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if there is no other constructor then only default constructor invoked.
 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what confuses me is "initializes the instance variables".

If it is "new" that "initializes the instance variables", then the 2nd statement would be false.

What do you guys think?
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shanel Jacob:
Which is true?



1) The default constructor invokes the no-parameter constructor of the superclass.

true

2) The default constructor initializes the instance variables declared in the class.

false

----------------------------------


K&B1.4 page 334 has the following statement.

1) The default constructor is a no-arg constructor with a no-arg call to super().

true

2) Instance methods and variables are only accessible after the super constructor runs.

true
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shanel Jacob:
Which is true?



K&B1.4 page 334 has the following statement.

1) The default constructor is a no-arg constructor with a no-arg call to super().

2) Instance methods and variables are only accessible after the super constructor runs.

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default constructor initializes the instance variables declared in the class.
Hi,
Once a call to super() by the subclass constructor is placed ,all the instance variables will be initialised to their default values. Only when that superclass constuctor and the subclass constructor calls completes
, the variables are initialised to their given values .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic