0

As of v0.6, solidity introduced abstract contracts.

Do they behave just like in all other languages - that is, they can't be initialised, can they?

1

Contracts marked as abstract in Solidity v0.6 and above cannot be initialised. Take the following files:

Foo.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.9;

contract Foo {
  function doStuff() external virtual pure returns(string memory) {
    return "do stuff";
  }

  function doMoreStuff() external virtual pure returns(string memory) {
    return "do more stuff";
  }
}

Bar.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.9;

import "./Foo.sol";

abstract contract Bar is Foo {
  function doStuff() external override pure returns(string memory) {
    return "do stuff from Bar.sol";
  }
}

Compile these two files in Remix and see what happens. Clicking the "Bytecode" button gives this warning in the bottom part:

Remix Screen Capture

That means that Solidity produced no bytecode for Bar.sol.

You may also want to read about the "virtual" and the "override" keywords.

| improve this answer | |

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.