aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""default" constructor" Watch ""default" constructor" New topic
Author

"default" constructor

Savio Mascarenhas
Ranch Hand

Joined: Nov 29, 2000
Posts: 108
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

Joined: Nov 09, 2000
Posts: 198
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "default" constructor