Link to home
Start Free TrialLog in
Avatar of Kennywen
Kennywen

asked on

close java class

i want to know how to close a java class?

e.g.
MyClass newClass = new MyClass();

how to close the above class?

When the class will be close if java cannot close it?

thanks
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

public class Main {
    public static void main(String[] args) {

new Main();
         
    }
}


This is the simplest class you can have almost. It will just be loaded and end.

If its a thread,. it will end when run() is finished.
Avatar of Kennywen
Kennywen

ASKER

that mean i will end by itself?? is there any way for us to end the new operator?
Not quite sure I follow what you mean by end the new operator. Objects in Java - and that means just about everything, cease to exist when they are not referenced by anythin else, so when they go out of  scope, they die.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In languages such as C++ there aer *de*structors, which are the opposite of constructors. In Java, you dont need that, because when an object is no longer pointed to (referenced) by any other object, then it is removed from memory by the garbage collector - System.gc() - automatically.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now, *you* are "repeating" *me*. Aren't you? ;)
Just added the extra line of code ;-)
>> Just added the extra line of code ;-)

mayankeagle, in fact I was talking to krakatoa :)
Oh.... I thought the "candidate for garbage-collection ". Anyways ;-)
Why a B :-(
Yeah, I also wonder...
Sometimes people think that the grades relate for the difficulty of the question.
But that isn't the case. If the answer is good an to the point it deserves an A.

Anyway, thanks for accepting.
Yeah, it also makes no difference to the questioner as they only spend as many question-points as they allocated to the question. Some closing help here:

https://www.experts-exchange.com/help/closing.jsp