Kotlin Basics
Kotlin Basics - Important Points
| 11. | What is the difference between a class and an object in Kotlin? |
|---|
A. A class is a blueprint for creating objects, while an object is a singleton instance of a class.
B. A class is a singleton instance of an object, while an object is a blueprint for creating classes.
C. There is no difference between a class and an object in Kotlin.
D. A class and an object are both used to create instances of a class.
View Answer Discuss Work SpaceAnswer: option a
Explanation:
| 12. | Which of the following is an example of inheritance in Kotlin? |
|---|
A. class MyClass {}
B. interface MyInterface {}
C. class MySubclass : MyClass {}
D. All of the above
View Answer Discuss Work SpaceAnswer: option c
Explanation:
| 13. | What is the difference between a primary constructor and a secondary constructor in Kotlin? |
|---|
A. A primary constructor is called before any secondary constructors, while a secondary constructor is called before the primary constructor.
B. A primary constructor is defined inside the class definition, while a secondary constructor is defined outside the class definition.
C. A primary constructor takes parameters that are used to initialize properties, while a secondary constructor can have additional logic or functionality.
D. There is no difference between a primary and a secondary constructor in Kotlin.
View Answer Discuss Work SpaceAnswer: option c
Explanation:
| 14. | What is the difference between a range and an array in Kotlin? |
|---|
A. A range is a collection of values between two endpoints, while an array is a fixed-size collection of elements.
B. A range is a fixed-size collection of elements, while an array is a variable-size collection of elements.
C. There is no difference between a range and an array in Kotlin.
D. A range and an array are both used to store collections of values.
View Answer Discuss Work SpaceAnswer: option a
Explanation:
| 15. | Which of the following is true about higher-order functions in Kotlin? |
|---|
A. Higher-order functions take other functions as parameters or return functions as results.
B. Higher-order functions are only used for mathematical calculations.
C. Higher-order functions are not supported in Kotlin.
D. Higher-order functions are used to create singleton objects.
View Answer Discuss Work SpaceAnswer: option a
Explanation: