Static modifier in an attribute

Asked

Viewed 207 times

0

I’m wondering if the Static modifier necessarily needs to be in the same package as the other classes in my project.

Example: I have a class called user within the user package and another class called valuesConstants within the Methodosutes package. The problem is that I am unable to call the static variable CONSTANT VALUE of the class of the same name in the class Usuarios.

  • Is there an error, could you give some more details? Or code how you are trying to access the constant? It may be a line

  • no, no mistake, actually it’s just a doubt I have. I usually bypass it using get methods to return me the value

  • 3

    Static is not about visibility, but whether the variable will exist only when there is an instance or whether it exists independently of it. What defines visibility are the private, public modifiers and when it is without modifier, which is the Packet visibility.

  • then if she has the public modifier in another package I will still have access to the value it contains?

  • boot a code @Alexsusama, sometimes it’s something simple

Show 2 more comments

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.