• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"default" constructor

 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following(two)are true about the "default" constructor ?
a)It is provided by the compiler only if the class does does not define any constructor .
b)It initializes the instance members of the class
c)It calls the default 'no-args' constructor of the superclass
d)It initailizes instance as well as class fields of the class
e)It is provided by the compiler if the class does not define a 'no-args' constructor
The answer mentioned was (a) & (c).Should'nt (a)&(b) be the answer ???
In (c),the "default" constructor calls the 'no-args' constructor of the superclass,which may or may not be the "default" construtor(not neccessarily the "default" constructor).
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The meaning of "default" constructor is that, if a class does not provide a constructor, then the java compiler provides an implicit constructor. This constructor is a no-arg constructor and its access specifier is that of the class. That is if a class is public then the access specifier of this "implicit constructor is public.
a)It is provided by the compiler only if the class does does not define any constructor .
True. Answer above.
b)It initializes the instance members of the class
False. This is not the functionality of the "default" constructor.
c)It calls the default 'no-args' constructor of the superclass
True. Any constructor whether is an implicit or provided by the programmer calls the super's constructor and in the latter case if a super() call is not made explicitly in any programmer-defined constructor
d)It initailizes instance as well as class fields of the class
False
e)It is provided by the compiler if the class does not define a 'no-args' constructor
False. It is provided by the compiler when the class does not define ANY constructor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic