• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this keyword usage

 
harish Jodh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic