• 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 constructors

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one is from the javacertificate mock exam.
Which of the following statements about default constructors are true? [Check all correct answers]


1. A default constructor is automatically provided by the compiler if no other class constructors are declared.
2. A default constructor does not have any parameters.
3. A default constructor is given a private access modifier when the class is declared with a private access modifier.
4. A default constructor declares a throw clause.
5. A default constructor invokes the superclass constructor with no arguments.

Feedback:
Answer 1,2,3 and 5 are correct.

Answer 3 is ambiguous because we cannot assume whether this question is about top-level classes or includes inner classes as well. Since a top-level class cannot be declared private or protected the statement seems true. what should one answer if such a question is posed in the Actual exam.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Top level classes can't have private modifier so if it says - "if they are given private modifier" it means they are referring to the inner classes hence 3rd answer would be expected by the questioner...
Though other views might differ here...
Regards
Maulin
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
" A default constructor is given a private access modifier when the class is declared with a private access modifier."
This question is very generalized about classes , does not specify Top level or Inner class. I would say in such cases , we can check for both possibilities like if the above statement is true for TopLevel class or Inner class. Since they have given the clue "private modifier of the class" implicitly says about inner class. So this statement is true for inner class. Questions are tricky and not specific always.
 
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic