Pergunta de entrevista da empresa Deloitte

Can we use the static variables inside static methods?

Respostas da entrevista

Sigiloso

10 de fev. de 2022

There are some rules : A local variable can not be static : class test { static int a = 10; static void m1() { static int b=20; // this line will give error , because local variable can not be static . System.out.println(a); // this will give outpur 10. } }

1

Sigiloso

6 de abr. de 2021

You cannot use static variable in the static method because JVM tries to allocate space for the static variable which he already allocated to the method inside which the static variable is declared.

17