Go language interfaces are different from other languages. In Go language, the interface is a custom type that is used to specify a set of one or more method signatures and the interface is abstract, so you are not allowed to create an instance of the interface. But you are allowed to create a variable of an interface type and this variable can be assigned with a concrete type value that has the methods the interface requires. Or in other words, the interface is a collection of methods as well as it is a custom type. To read more about Interfaces, please refer to the article Interface in Golang
There are two structures and one interface. One structure is for gfg course details and another structure is for contest details. One interface is having get_name method which will return names of course and contest. With the help of the interface, we will access the structure’s variable as we don’t want to access the structure’s variable from outside.
Example 1: This program will take 2 inputs.
Enter course name: DBMS Enter contest name: DBMS Is same subjects in course and contest: true
Example 2: This program will take 2 inputs.
Enter course price: 1000 Enter Coupon Price: 700 Is the course is free: false
- Promoted Fields in Golang Structure
- strings.Fields() Function in Golang With Examples
- How to compare Structs with the Different Values Assigned to Data Fields in Golang?
- reflect.Interface() Function in Golang with Examples
- How to check pointer or interface is nil or not in Golang?
- Function that takes an interface type as value and pointer in Golang
- Mathematics | Rings, Integral domains and Fields
- Sort array of objects by object fields in PHP
- Scala | Controlling visibility of constructor fields
- Difference between private keyword and private fields in TypeScript
- How to add input fields dynamically on button click in AngularJS ?
- How to detect the duplication of values of input fields ?
- How to declare and access pointer variable in Golang?
- CSS | User Interface
- Perl | DBI(Database Independent Interface) Module Set - 1
- What is the difference between interface and type in TypeScript ?
- What is AUI(Attachment Unit Interface)?
- What is ODI(Open Data link Interface)?
- HTML | AbsoluteOrientationSensor Interface
- How to check interface type in TypeScript ?
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.