Logo

Golang Questions Set 8:

Quiz Mode

Which keyword is used to implement an interface in Go?

1
2
3
4

Solution:

What is the purpose of an empty interface in Go?

1
2
3
4

Solution:

What is the output of the following code?

package main

import "fmt"


func main() {

   var x []int

   fmt.Println(len(x))

}

1
2
3
4

Solution:

What is the purpose of the "net.Conn" interface in Go?

1
2
3
4

Solution:

What will be the output of the following code?

package main

import "fmt"

func main() {

  var x [3]int = [3]int{1, 2, 3}

  y := x

  y[1] = 4

  fmt.Println(x[1], y[1])

}


1
2
3
4

Solution:

What is the purpose of the "sort.Interface" interface in Go?

1
2
3
4

Solution:

What is the purpose of the "fmt.Stringer" interface in Go?

1
2
3
4

Solution:

Can a struct implement multiple interfaces in Go?

1
2
3
4

Solution:

What will be the output of the following program?

package main


import (

"fmt"

)


func main() {

var x interface{} = 5

var y interface{} = "Hello"

fmt.Println(x.(int) + y.(string))

}



1
2
3
4

Solution:

Which of the following is not a valid way to implement an interface in Go?

1
2
3
4

Solution: