• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Public Static confusion.

 
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?
 
author
Posts: 23887
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
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.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic