menu

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.

Discuss Work Space

Answer: option a

Explanation:

In Kotlin, a class is a template or blueprint for creating objects, while an object is a single instance of a class that is created at runtime and cannot be instantiated again.

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

Discuss Work Space

Answer: option c

Explanation:

Inheritance allows you to create a new class based on an existing class, inheriting its properties and methods.

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.

Discuss Work Space

Answer: option c

Explanation:

The primary constructor is defined inside the class definition and is responsible for initializing the properties of the class. A secondary constructor can have additional logic or functionality and must call the primary constructor using the "this" keyword.

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.

Discuss Work Space

Answer: option a

Explanation:

A range is a collection of values between two endpoints, while an array is a fixed-size collection of elements that can be accessed using an index.

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.

Discuss Work Space

Answer: option a

Explanation:

Higher-order functions are a powerful feature of Kotlin that allows you to pass functions as arguments to other functions or return functions as results.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now