• 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

"default" constructor

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic