Forums Register Login

Help with this pointer

+Pie Number of slices to send: Send
public class First{
public void showData(){
System.out.println("Can't emagine life without java");
}
public static void main(String[] args){
First p=new First();
p.showData();//work well
this.showData()//Not work
}
}

Helo sir in the above code as we know taht "this" is also an object of First class as same as p then why calling this.showData() doesn't work.

withe regard

Arun kumar maalik
+Pie Number of slices to send: Send
"this" (meaning "this object") should be used for non-static methods (object level methods). you cannot use "this" in a static method (aka class level method).





[ July 11, 2006: Message edited by: ak pillai ]

[ July 11, 2006: Message edited by: ak pillai ]

[ July 11, 2006: Message edited by: ak pillai ]
[ July 11, 2006: Message edited by: ak pillai ]
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 525 times.
Similar Threads
Why Thread.start()?
why we not override method of HttpServlet
Help with constructor
Is there a way to invoke new methods defined in Anonymous classes?
package problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:56:05.