I have two classes, A
and B
. The A
class needs to access all existing static variables in B
. How to do this import?
I found a lot with get
, however it does not look like this. I'm a beginner and I'm lost.
I have two classes, A
and B
. The A
class needs to access all existing static variables in B
. How to do this import?
I found a lot with get
, however it does not look like this. I'm a beginner and I'm lost.
independent if you instanciar
class B or use via import
...
you will only be able to access its attributes if they are declared as public static .
If you instantiated class B, you probably ran into the following error!
Change visibility of 'variable' to public
Creat getters and setters for 'variable'
If you access via Import
, you only need to call it this way:
Ex: B.Nome
or Class.Atributo
Put this in class A
:
import static B.*;
To access all existing static variables in B you should write the following import
:
import static B.*;
Thus, class A will have access to all members declared as static
that A can see. Member States means "variables" and "methods".
If you wanted just one variable, you could do something like this:
import static B.VARIAVEL_ESTATICA;