Professional Documents
Culture Documents
&
Package in Java
Destructor
Destructor in programming
• A destructor, in programming, is a special method or function within a
class that is automatically invoked when an object is destroyed or life
time of object ends.
• Purpose: Managing memory and resources
• In languages like C++ and Python, destructors are used to deallocate
memory, close file handles, release network connections, or perform
any other necessary cleanup tasks associated with an object.
• If System resources are not properly managed it will have impact on
system performance
Object life cycle
• Creation: Constructor
• Usage: Object methods
• Destruction: Garbage Collection
Garbage Collection
Create two objects e1 and e2 and pass the salary to the constructor