• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a friendly class with public constructor and methods

 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just wondering the effects of a modifer of a class.
If the class itself is friendly or package private, can its methods, constructors and fields be declared pubic?
If so, can classes outside the package invode those methods and constructors or access the fields??
What's the effect of the modifier of a class?
 
Junilu Lacar
Bartender
Pie
Posts: 7800
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to Java in General (Beginner)
Junilu
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class declared without an access modifier ("friendly" or "package" access) is only visible to other classes/interfaces in the same package. Making the methods public does not change this. So, no, classes outside the package cannot invoke the methods of this class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic