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?
- How to check pointer or interface is nil or not in Golang?
- reflect.Interface() Function in Golang with Examples
- How to declare and access pointer variable in Golang?
- Function that takes an interface type as value and pointer in Golang
- Sort array of objects by object fields in PHP
- Scala | Controlling visibility of constructor fields
- How to detect the duplication of values of input fields ?
- Mathematics | Rings, Integral domains and Fields
- How to add input fields dynamically on button click in AngularJS ?
- Difference between private keyword and private fields in TypeScript
- CSS | User Interface
- What is AUI(Attachment Unit Interface)?
- HTML | AbsoluteOrientationSensor Interface
- What is ODI(Open Data link Interface)?
- What is the difference between interface and type in TypeScript ?
- How to get Synchronize access to the Array in C#
- Perl | DBI(Database Independent Interface) Module Set - 1