ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Is it possible to access non static variable inside the static block, and how?

user-image
تم إضافة السؤال من قبل pushpa latha ANNELA , data verification , success solutions
تاريخ النشر: 2016/06/14
Vijay Katariya
من قبل Vijay Katariya

if we pas the object of  the class in the static block the we access the non static variable  in the static block

Mostafa ElSheikh
من قبل Mostafa ElSheikh , Software Development Engineer II (L5) , Amazon

Actually, It's not possible to access a non-static variable inside a static block.

Static variable is a class variable; you can access it through the name of class without creating an object from that class.

Example: MyClass.myVariable = 5;

Moreover, you can access it through the reference of the object of that class

Example: myRef.myVariable = 5;

They're strictly the same.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟