Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Declaring variables in constructor?  RSS feed

 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
If we are declaring/initializing a variable in constructor what type of variable is that local or class ? and where it is going to store in heap or stack


thanks in advance
 
Henry Wong
author
Sheriff
Posts: 23260
124
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you are declaring, obviously, it is a local variable. If you are initializing, then it depends on how the variable was declared.

Whether a variable is on the heap or stack depends on the type of variable. Beginning with Java 6, this is further complicated with escape analysis.

Henry
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
What a show! What atmosphere! What fun! What a tiny ad!
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!