Interface in Solidity

Interface in Solidity

This blog explain about interface that we have in solidity language.

In interface, all the functions does not have implementation (function body). Below is one of the example.

pragma solidity ^0.4.0;
interface member{
function setName() public returns (string);
function setAge() public returns (uint);
}

Below is the difference between abstract contract and interface.

Abstract Contract: Contract become abstract when at least one of the function in that contract does not have
implementation.

Interface: In interface all the functions does not have implementation.

Another contract can inherit interface and need to implement all of the functions.

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

No Comments

Post a Reply

Inquire Now
close slider