This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Declaring variables in constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Declaring variables in constructor?" Watch "Declaring variables in constructor?" New topic

Declaring variables in constructor?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
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

Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Henry Wong

Joined: Sep 28, 2004
Posts: 19342

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
I agree. Here's the link:
subject: Declaring variables in constructor?