fbpx

Learn Solidity: Abstract Contracts in Solidity

In this post, we will learn what are abstract contracts & how to use them in Solidity Language.
Notice: This is one of the multi-post series of Learn Solidity - Build Decentralized Application in Ethereum. This is an attempt to teach you all about Solidity - A Programming Language for Ethereum Based Smart Contracts. If you want to take this as a video course please signup using below button.
pragma solidity 0.4.8;

// These abstract contracts are only provided to make the
// interface known to the compiler. Note the function
// without body. If a contract does not implement all
// functions it can only be used as an interface.

// Let me write an abstract contract with a single function and then extend it 
// in the new contract and then override it there.
contract Feline {
	// This is how we write the abstract contract 
    function utterance() returns (bytes32);
}

// inherit the contract in cat and then override the function utterance with some full definition
contract Cat is Feline {
    function utterance() returns (bytes32) { return "miaow"; }
}
Previous: Fallback Function in Solidity Next: Creating a Contract with new Operator in Solidity