|
-
Jun 5th, 2006, 10:00 AM
#1
Thread Starter
Fanatic Member
Constructor call question
I have a chunk of code in class Aquarium that looks like this:
Code:
public static void main(String[] args)
{
new Aquarium();
}
I know that "new Aquarium()" is used to create a new Aquarium object, but what is the scope of this new object? Why would you want to do this?
Thanks.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Jun 5th, 2006, 12:38 PM
#2
Re: Constructor call question
If you don't want to hold a reference to the object, do that.
for example, if you place all code necessary to work with a JFrame in it's constructor. You want need to hold a reference to it in the main program
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 5th, 2006, 03:23 PM
#3
Thread Starter
Fanatic Member
Re: Constructor call question
So when this constructor is called, is this object immediately destroyed or does it hang around until main is completed?
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Jun 5th, 2006, 06:47 PM
#4
Re: Constructor call question
This depends on what type is the object...
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 6th, 2006, 09:41 AM
#5
Thread Starter
Fanatic Member
Re: Constructor call question
This depends on what type is the object...
I am sorry, but I don't quite know what you mean. I am sort of new to Java.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Jun 6th, 2006, 11:20 AM
#6
Re: Constructor call question
Every object created with new hangs around at least until there are no more references to it, and then some (until the GC runs and kills it). In other words, object lifetime in Java is non-deterministic: you cannot predict it exactly.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|