Logo

Golang Questions Set 16:

Quiz Mode

Which of the following is a correct example of embedding a struct within another struct in Go?

1
2
3
4

Solution:

What is the output of the following Go code?

package main

import "fmt"

func main() {

   var ptr *int

   var num int = 10

   ptr = &num

   *ptr = 20

   fmt.Printf("%d\n", num)

}

1
2
3
4

Solution:

What is defer in Go?

1
2
3
4

Solution:

What is a method set in Go?

1
2
3
4

Solution:

What is composition in Go?

1
2
3
4

Solution:

What is abstraction in Go?

1
2
3
4

Solution:

Which of the following is true about encapsulation in Go?

1
2
3
4

Solution:

What is polymorphism in Go?

1
2
3
4

Solution:

What is the output of the following Go code snippet if an error occurs while opening the file?

file, err := os.Open("file.txt")

defer file.Close()


if err != nil {

  fmt.Println("Error:", err)

} else {

  fmt.Println("File opened successfully.")

}



1
2
3
4

Solution:

What is the difference between a value receiver and a pointer receiver in Go?

1
2
3
4

Solution: