Constructor and Destructor

Total Post:113

Points:791

 642  View(s)
Ratings:
Rate this:

Difference between constructor and Destructor in Java?

  1. Re: Constructor and Destructor

    Constructors: 

     They are special class function which is initializing every objects. means its a object creater for different operators. 

    Notation : mindstick()

    class mindstick 

     int x;
     public:
    mindstick(); //Constructor
    };

    They are three types: 

    1-Default

    2-Parametrized

    3-Copy

    Overloading process would be going through construction.

    Destructors: 

    they are special class for destroy the objects as soon as the scope of objects in end.

    Notation: ~mindstick() 

    class mindstick() 
    {
     public:
     ~mindstick();
    };

    Happy Coding :)

  1. Re: Constructor and Destructor

    Difference between constructor and Destructor :

    Constructor :

    • Constructor are special types of method that are used to initialize the property and behavior of any object.
    • The constructor is called automatically when objects are created.
    • Constructor contain many arguments or parameters.
    • Constructor always called in serial order.
    • A constructor can be overloaded.
    • You can define multiple constructor in the same class.


    Destructor:

    • In other word you can say that destructor is also special types of method that is used to destroy the scope of any object. And it’s also denoted by a tilde symbol.
    • Destructor called automatically when the program is terminated (or exit).
    • Destructor can’t contain any arguments or parameters.
    • Destructor always called the reverse order of the constructor.
    • Destructor can’t be overloaded.
    • In terms of the destructor, you can define only single destructor in a class.

    Note :  Java doesn't support Destructor because it's a garbage collected language .



      Modified On Jun-11-2018 11:23:00 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.