Abstract Contract in Solidity

Abstract Contract in Solidity

This blog explain abstract contract that we have in solidity language.

Contracts are knows as abstract when one of the function in that contract lacks implementation. Below is one of the example.

pragma solidity ^0.4.0;
contract member{
string name;
function setName() public returns (string);
}

In case you have more than one function in smart contract and one of the function does not have implementation (no function body) then that contract is also abstract contract.

Another contract can inherit abstract contract and implement the function.

pragma solidity ^0.4.0;
contract member{
string name;
function setName() public returns (string);
}
contract teacher is member{
function setName() public returns(string){
return "Mark";
}
}

 

Abstract functions can't be complied.

If a contract inherits from an abstract contract and does not implement all non-implemented
functions by overriding, it will itself be abstract.

No Comments

Post a Reply

Inquire Now
close slider