let's say I have the following contract/solidity file:

pragma solidity ^0.4.20;

contract partOne {
    address public owner;
    function partOne() public {
        owner = msg.sender;

contract partTwo is partOne{
    uint public ownerBalance;
    function partTwo() public {
        ownerBalance = 500;

Now, constructor functions are runned once and only in the contract deployment. Will now both constructor functions run once and after that not being callable again? Or is it better to put everything in the second constructor function?


When you deploy partOne its constructor will be called once. When you deploy partTwo the partOne's constructor will be invoked before the partTwo's one both only once.


It is ok to have constructor in parent contract. It will be expecuted once, on deployment.

According to last solidity style guides - it is better to use constructor() {} instead of function partOne() {}.

  • I know that constructor is recommended to use. My question was only, if in my case both functions are runned only once.
    – dkb
    May 18 '18 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.