File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Jtips Quiz4 No.1: About default constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Jtips Quiz4 No.1: About default constructor" Watch "Jtips Quiz4 No.1: About default constructor" New topic
Author

Jtips Quiz4 No.1: About default constructor

yi miao
Greenhorn

Joined: Jun 29, 2001
Posts: 6
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?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtips Quiz4 No.1: About default constructor
 
Similar Threads
Implicitly given access modifier
Implicit Constructor
Private Class????
are constructors inherited?
Acceess Modifiers