Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Access for Classes.

 
Brit Wright
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All:
If there are two classes, say, C1 and C2, and both belong to default package, i.e, none of them are set to be in any specific package, can they access each others public, default, and protected members?
Class C1{
public f1(){ };
protected f2(){ };
}

Class C2{
public f3 () {};
protected f4 () {};
}
I am new to java. So, please, just mentor me even if you find my question bit silly...
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy
No, the question isn't silly. And you're absolutely right, even in the default package, if two classes are in the default package they can both access each other's public, default, and protected members.
cheers,
Kathy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic