Meaningless Drivel is fun!*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructor accessor" Watch "constructor accessor" New topic
Author

constructor accessor

Jason Li
Ranch Hand

Joined: Jun 24, 2001
Posts: 46
Hi, Pals, here is a question from JTips.net QUIZ4:
<code>
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?
</code>
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: 2370

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 ....

------------------
azaman


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Percy Densmore
Ranch Hand

Joined: Mar 06, 2001
Posts: 214
Jason,
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 www.javaranch.com/ubb/Forum24/HTML/003754.html
Hope this helps :-)
Percy
[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:
TestTest.java:6: 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: http://aspose.com/file-tools
 
subject: constructor accessor