• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Package access scope

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
william su
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok,thank you very much Abhishek Sawant!!

I have already understand.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic