File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructor accessor 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 "constructor accessor" Watch "constructor accessor" New topic

constructor accessor

Jason Li
Ranch Hand

Joined: Jun 24, 2001
Posts: 46
Hi, Pals, here is a question from QUIZ4:
public class Test {
double x, y;
Test() {
The No arguments constructor Test() has "default" access modifier ( i.e with no access modifier ). True or False?
The answer is false, but i think it should be true. Anybody give a light?

green horn
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2373

Hi Li,
What is meant Pals? Clarify.
Test() should have the default access modifier. I don't see any othe reason to be the answer false. Someone else ....


Ashik Uzzaman
Senior Software Engineer, TubeMogul, Emeryville, CA, USA.
Percy Densmore
Ranch Hand

Joined: Mar 06, 2001
Posts: 214
The way I understand it is, if a constructor has no access modifier, it takes on the access modifier of it's parent class, so to speak. Check out this previous discussion on the same topic
Hope this helps :-)
[This message has been edited by Percy Densmore (edited July 17, 2001).]
[This message has been edited by Percy Densmore (edited July 17, 2001).]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
This is incorrect.
It is true that the default constructor has the same access modifier as the class... but that only applies when you do not code a no parameter constructor!!!
In the example, the constructor will have a modifier of default (package) and will not be accesible from outside the package that the class is in. Example:

Will give this error message: Test() is not public in test.Test; cannot be accessed from outside package
Test t = new Test();
1 error

Tom - SCJP --- Co-Moderator of the Programmer Certification Forums

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jason Li
Ranch Hand

Joined: Jun 24, 2001
Posts: 46
Thank you all!
I agree. Here's the link:
subject: constructor accessor
It's not a secret anymore!