• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Jtips Quiz4 No.1: About default constructor

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given:
public class Test {
double x, y;

Test() {
super();
}
}
The No arguments constructor Test() has "default" access modifier ( i.e with no access modifier ). True or False?
The Author's answer is False. He says: If the class is declared public, then the default constructor is implicitly given the access modifier public. If the class is declared protected, then the default constructor is implicitly given the access modifier protected and if the class is declared private, then the default constructor is implicitly given the access private.
I think the anwser for this one is True. I understand the default constructor is given only when the class contains no construction declaration, and then the constructor's modifier is implicitly given as class's modifier. In this question, a constructor is already given, and its access modifier is default meaning its accessibility is package level. So I think the anwser should be True. Am I right?
Besides, I wrote a subclass of Test class in another package. When I compile, I got error message: constructor Test() is not public in class pakgname.classname. I think if the Test() is public, subclass in another package should be able to access it.
Any coments for this question?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's true that the default constructor is given the modifier of "public" if you don't code a default constructor. So I agree with you that the question is wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic