jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes this keyword usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "this keyword usage" Watch "this keyword usage" New topic
Author

this keyword usage

harish Jodh
Greenhorn

Joined: Nov 12, 2012
Posts: 1
hello,

could someone please help me understand why s2 and s3 dont get the value passed via constructor :


Output:
s1: Passed Value
s2 : local
s3: local
s4: Passed Value
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

harish Jodh wrote:hello,

could someone please help me understand why s2 and s3 dont get the value passed via constructor :


Because you set them before the c'tor is invoked, not inside the constructor. The fact that you put them after the c'tor in your source file doesn't mean they get executed after the c'tor is run. All those initializer lines are run each time an object is created, before any c'tor is invoked, regardless of where they're placed in the file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: this keyword usage
 
Similar Threads
Strings
String concatenation
== with Strings is giving a different result
string assignment
difference between == and equal() in sting