Is there a way to call the second operate() function?
Yes - you can qualify it with Foo.this
to refer to the enclosing instance of Foo
:
operatedNumber = Foo.this.operate(x,y);
Question
Consider following class:
class Foo
{
private class Bar
{
int operatedNumber;
Bar(int x, int y)
{
operatedNumber = operate(x,y);
}
int operate(int x)
{
return x*2;
}
}
public int operate(int x, int y)
{
return x+y;
}
public Foo()
{
Bar b = new Bar(3,5);
}
}
I am getting compile time error The method operate() is not applicable for the arguments (int, int).
Is there a way to call the second operate()
function?
Solution
Is there a way to call the second operate() function?
Yes - you can qualify it with Foo.this
to refer to the enclosing instance of Foo
:
operatedNumber = Foo.this.operate(x,y);