• Post Reply Bookmark Topic Watch Topic
  • New Topic

this keyword brief explanation and why this program shows error message  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is the error message? It helps us tremendously if you TellTheDetails.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

As Fred has said it's important to give all the information. The easier you make it for other people to understand the problem you are facing the more likely they are to help you.

In this case, however, your problem is on line 10. You cannot use the reserved word 'this' in a static method, see http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
BTW I wouldn't recommend calling your class 'This' it is just confusing.
 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"This" is your class name while "this" is a reference to the current object.
So you should use t.jk() because that's the name of the object with which you're calling jk().
Iniside the class if you use "this" then it's with respect to the calling object!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!