Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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 .
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic