How to import all static variables from another class?

0

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.

    
asked by anonymous 04.07.2017 / 17:55

3 answers

2

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

    
04.07.2017 / 19:35
5

Put this in class A :

import static B.*;
    
04.07.2017 / 18:08
1

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;
    
04.07.2017 / 20:31