Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Simple Object Question
J. Ryan
Greenhorn
Posts: 21
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have a simple question about when memory is actually allocated. What is the difference between the following two code snippets?
public class Test { Object myObj = new Object(); public Test() {} }
and
public class Test { Object myObj; public Test() { myObj = new Object(); } }
Thanks.
[ June 30, 2007: Message edited by: J Ryan ]
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No difference at all, actually. Instance variable initializers like your "= new Object()" are compiled into the constructors of the class.
[Jess in Action]
[AskingGoodQuestions]
J. Ryan
Greenhorn
Posts: 21
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks!
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
using this in a class itself
From the office.
From main method to contractor, it is possible?
Possible Memory Leak ?
How do I add a object (copy) to a que or hashmap, and not a reference?
More...