class A{
int x,y;
class B{
void setValues(int x,int y){ this.x=x;this.y=y;}
}
void print(){
B b=new B();
b.setValues(2,3);
System.out.println(x+y);
}
}为什么说找不到符号x,y。。
int x,y;
class B{
void setValues(int x,int y){ this.x=x;this.y=y;}
}
void print(){
B b=new B();
b.setValues(2,3);
System.out.println(x+y);
}
}为什么说找不到符号x,y。。
class B{
void setValues(int x,int y){ this.x=x;this.y=y;}
}
这里面得this指针指向的是B的对象,而非A对象,B对象没有x,y属性,因此this.x,this.y当然不存在。谢谢
public class DDD
{
public static void main(String[] args)
{
A a = new A();
a.print();
}
}class A
{
int x, y; class B
{
void setValues(int x, int y)
{
A.this.x = x;
A.this.y = y;
}
} void print()
{
B b = new B();
b.setValues(2, 3);
System.out.println(x + y);
}
}