0

In this code here, does theRun() function act as a constructor?

contract theRun {
                
        address private admin;
        
        function theRun() {
            admin = msg.sender;
        }
}

3 Answers 3

0

Are you sure that compiler is not giving you any error? Because you haven't mentioned scope in your theRun(). And no, the theRun() won't act as constructor.

0

Depending on your version, Since solidity 0.4.23, constructors needs to be specified using the constructor keyword, constructors are optional.

So you can declare your constructor using a function with the same name as your contract, IF you’re using a version older than 0.4.23

0
0

No it doesn't.

The most and obvious reason is that a function can never have the same name as the contract.

  • Function can only be called at a defined time to perform a specific task and it requires a valid return type.
  • Constructor initializes a created object and have no return type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.