File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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: 18548

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
subject: Declaring variables in constructor?
Similar Threads
Cannot Figure Out This Syntax Error
Errors when reading and writing from a text file - any help!!
Overloading constructors.
char to int