This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with this pointer  RSS feed

 
Arun kumar Maalik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • 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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!