File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which statement is true for default Constructor?

 
Shanel Jacob
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both are true.
 
Anthony Karta
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • 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".
 
Ashwini Ghamandi
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there is no other constructor then only default constructor invoked.
 
Shanel Jacob
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Ivan Rebrov
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Naveen Zed
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
prarthana reddy
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • 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 .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic