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?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityAs 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?
Contracts marked as abstract in Solidity v0.6 and above cannot be initialised. Take the following files:
// 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";
}
}
// 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:
That means that Solidity produced no bytecode for Bar.sol
.
You may also want to read about the "virtual" and the "override" keywords.