Abstract contracts are contracts that have at least one function without its implementation. An instance of an abstract cannot be created. Abstract contracts are used as base contracts so that the child contract can inherit and utilize its functions. The abstract contract defines the structure of the contract and any derived contract inherited from it should provide an implementation for the incomplete functions, and if the derived contract is also not implementing the incomplete functions then that derived contract will also be marked as abstract. In Solidity there is no abstract keyword for creating an abstract contract, a contract itself becomes abstract if it has unimplemented functions.
Example: In the below example, an abstract contract is created which is inherited by another contract that has implemented all the functions of the abstract contract. Abstract contract instance is created in the calling contract and an object of child contract is created. Using the object of child contract all the abstract functions that are implemented in the child contract are invoked.
Here, abstractContract contract is an abstract contract that has some functions without their implementation, and derivedContract is its child contract. The getStr() and setValues() functions takes string and values, while the add() function adds the values of setValues() function. abs is an object of abstractContract which creates an instance of derivedContract in call contract that uses the variables of the contract and calls the functions.
- Steps to Execute Solidity Smart Contract using Remix IDE
- Creating a Smart Contract that Returns Address and Balance of Owner using Solidity
- What is Smart Contract in Solidity?
- How to use MetaMask to Deploy a Smart contract in Solidity (Blockchain)?
- How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
- What is Escrow Smart Contract?
- What is Wallet Smart Contract?
- Smart Contract to Store Employee Details
- Interacting With Ethereum Smart Contract Using Web3js
- Deploying Smart Contract on Test/Main Network Using Truffle
- Solidity - Types
- Solidity - Functions
- What are Events in Solidity?
- Solidity - Inheritance
- Solidity - Polymorphism
- Solidity - View and Pure Functions
- Solidity - Encapsulation
- How to Install Solidity in Windows?
- Solidity - While, Do-While, and For Loop
- Solidity - Break and Continue Statements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.