+ 6

Can we access a non-static variable in the static context on java?

18th Jun 2021, 4:01 AM
RuBeen Dahal👿
2 Respostas
+ 1
why should be easy to understand. accessing non-static elements means accessing members of an object of the class to which the static element belongs. but since the static element is shared among all the objects of that class and exists in the moment in which a class is defined without the need for an object to be instantiated, how can a static method choose and access non-static elements, therefore the members of a object that may not exist, be one or n?
18th Jun 2021, 5:21 AM
Ciro Pellegrino
Ciro Pellegrino - avatar
0
You have to make the objects of them to acess in main
18th Jun 2021, 10:53 AM
Atul [Inactive]