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?
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
posted
0
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
posted
0
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