Meaningless Drivel is fun!
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
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: 20521

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?
It's not a secret anymore!