I understand that this refers to the current object. So instead of using objectname.fun(objectname.nonstaticmember)
, why can't I use objectname.fun(this.nonstaticmember)
Please refer example below, and see the last two comments at the end.
public class Question
{
int data;
void myfun(int data)
{
System.out.println("data=="+data);
}
public Question(int data)
{
this.data = data;
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
{
Question question = new Question(10);
//question.myfun(question.data);//WORKS
question.myfun(this.data);//DOES NOT WORK
}
}