• Post Reply Bookmark Topic Watch Topic
  • New Topic

Public Static confusion.  RSS feed

 
Shelby Simpson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering why it would matter if I put public or private in front of a static method or variable. There a class variable and method so does it matter?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shelby Simpson wrote:I was wondering why it would matter if I put public or private in front of a static method or variable. There a class variable and method so does it matter?



Not sure of the confusion. Public static variables and methods can be accessed from other classes. Private static variables and methods can *not* be accessed from other classes.

Are you saying that this access control serves no purpose?

Henry
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shelby Simpson wrote:I was wondering why it would matter if I put public or private in front of a static method or variable. There a class variable and method so does it matter?


Why do you think it's any different marking a member variable public or private if it's static vs. non-static?

The access modifiers are orthogonal to static vs. non-static. They have the same meaning regardless of whether the member in question is static or not.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!