• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Help with this pointer

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic