Solidity introduced abstract contractsin v0.6.
Do they behave just like in all other languages? They can't be initialized, can they?
Solidity introduced abstract contractsin v0.6.
Do they behave just like in all other languages? They can't be initialized, 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.