سلام به دوستان
تو برنامه زیر داخل متد testOne یه local class نوشتم به نام inTest که در داخل اون یه متد دیگه به نام inTestOne پیاده سازی شده .
همون طور که میبینید متغییر x داخل متد shadow شده . من میخوام از داخل متد inTestOne به متغییر x مربوط به متد testOne دسترسی داشته باشم .
اما وفتی با this این کارو میکنم ارور میگیره (خط 8th که کامنت شده) . چطوری میتونم این کارو کنم؟
public class Test {
int testOne(){ //member method
int x=5;
class inTest // local class in member method
{
void inTestOne(int x){
System.out.print("x is "+x);
// System.out.print("this.x is "+this.x);
}
}
inTest ins=new inTest(); // create an instance of inTest local class (inner class)
ins.inTestOne(10);
return 0;
}
public static void main(String[] args) {
Test obj = new Test();
obj.testOne();
}
}