File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package access scope 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 "Package access scope" Watch "Package access scope" New topic
Author

Package access scope

william su
Greenhorn

Joined: Feb 08, 2010
Posts: 11

I think the answer is "Compilation error, in package trunk3 at line 4".Because the Account Constructor is default access.It only can be access in package trunk1.
But,i am wrong.
guys,who can tell me why?
Thanks a lot!!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Welcome to JavaRanch.

Please note that if you copy a question from a book, mock exam or other source, we require that you QuoteYourSources - in other words, please tell us where you copied this question from.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
william su
Greenhorn

Joined: Feb 08, 2010
Posts: 11
Sorry,Jesper Young,I forgot it.

It comes from JavaChamp.

http://www.javachamp.com/questions/packages-and-access-scope-in-java.xhtml

Thanks a lot.
Abhishek Sawant
Greenhorn

Joined: Feb 21, 2010
Posts: 13
Compilation error, in package trunk2 at line 2
Compilation error, in package trunk3 at line 4.
These 2 are correct answers...

Reason:
Constructor can be default. So option 3 is not wrong. Anything declared as default has access in that package only. Not even in the subclasses out of package(protected members have this property). In package trunk2, when you try to extend some class from package trunk1, compiler will complain as that class has default constructor. And as I said above, you cannot access anything that has default tag, outside the package, even if you extend the class from first package.

I hope this point is clear to you.

Now, a line in Tester file:
Account c = new Account();
This line is trying to do same as we discussed above. Accessing default members outside package. Compiler won't allow it.

If you still have any doubt, please ask for the same.

Regards,
Abhishek.
william su
Greenhorn

Joined: Feb 08, 2010
Posts: 11
ok,thank you very much Abhishek Sawant!!

I have already understand.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package access scope