Constructor

Solidity

परिभाषा

Constructor एक special function है जो contract deployment के time पर केवल एक बार execute होता है। यह contract की initial state set करने के लिए use होता है (जैसे owner assign करना, initial values set करना)। Constructor optional है और इसे inherit भी किया जा सकता है।

English version

Constructor is a special function that executes only once during contract deployment. It is used to set the initial state of the contract (like assigning an owner, setting initial values). Constructor is optional and can be inherited.

Code Example

contract MyToken {
    string public name;
    address public owner;

    constructor(string memory _name) {
        name = _name;
        owner = msg.sender;
    }
}

// Déploiement
MyToken token = new MyToken("MyToken");

संबंधित शब्द

Solingo पर इस concept को practice करें

Constructor को interactive exercises और integrated IDE के साथ master करें।

मुफ्त में शुरू करें