
- Solidity Tutorial
- Solidity - Home
- Solidity - Overview
- Solidity - Environment Setup
- Solidity - Basic Syntax
- Solidity - First Application
- Solidity - Comments
- Solidity - Types
- Solidity - Variables
- Solidity - Variable Scope
- Solidity - Operators
- Solidity - Loops
- Solidity - Decision Making
- Solidity - Strings
- Solidity - Arrays
- Solidity - Enums
- Solidity - Structs
- Solidity - Mappings
- Solidity - Conversions
- Solidity - Ether Units
- Solidity - Special Variables
- Solidity - Style Guide
- Solidity Functions
- Solidity - Functions
- Solidity - Function Modifiers
- Solidity - View Functions
- Solidity - Pure Functions
- Solidity - Fallback Function
- Function Overloading
- Mathematical Functions
- Cryptographic Functions
- Solidity Common Patterns
- Solidity - Withdrawal Pattern
- Solidity - Restricted Access
- Solidity Advanced
- Solidity - Contracts
- Solidity - Inheritance
- Solidity - Constructors
- Solidity - Abstract Contracts
- Solidity - Interfaces
- Solidity - Libraries
- Solidity - Assembly
- Solidity - Events
- Solidity - Error Handling
- Solidity Useful Resources
- Solidity - Quick Guide
- Solidity - Useful Resources
- Solidity - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Solidity - Interfaces
Interfaces are similar to abstract contracts and are created using interface keyword. Following are the key characteristics of an interface.
Interface can not have any function with implementation.
Functions of an interface can be only of type external.
Interface can not have constructor.
Interface can not have state variables.
Interface can have enum, structs which can be accessed using interface name dot notation.
Example
Try the following code to understand how the interface works in Solidity.
pragma solidity ^0.5.0; interface Calculator { function getResult() external view returns(uint); } contract Test is Calculator { constructor() public {} function getResult() external view returns(uint){ uint a = 1; uint b = 2; uint result = a + b; return result; } }
Run the above program using steps provided in Solidity First Application chapter.
Note − Select Test from dropdown before clicking the deploy button.
Output
0: uint256: 3
Advertisements