2

Solidity introduced abstract contractsin v0.6.

Do they behave just like in all other languages? They can't be initialized, can they?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143

1 Answers1

3

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.

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143