top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we use "this" keyword without creating object of class in java?

+1 vote
392 views
Can we use "this" keyword without creating object of class in java?
posted Sep 12, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Yes, because the this object reference can be used inside any non-static method to refer to the current object

The common uses of the this reference are:
To pass a reference to the current object as a parameter to other methods

someMethod(this);

To resolve name conflicts Using this permits the use of instance variables in methods that have local variables with the same name

answer Sep 13, 2014 by anonymous
...