To pass as an argument in the method

The this keyword can also be passed as an argument in the method. It is mainly used in the event handling. Let's see the example:


\begin{lstlisting}
class S2{
void m(S2 obj){
System.out.println(''method is ...
...void main(String args[]){
S2 s1 = new S2();
s1.p();
}
}
\end{lstlisting}

Output:


\begin{lstlisting}
method is invoked
\end{lstlisting}