Kotlin Interview Questions

Kotlin Interview Questions :

Kotlin Interview Questions

1) What is Kotlin?

  • Statically-typed programming language.
  • Runs on the Java Virtual Machine.
  • Compiled both Java source code and LLVM compiler.
  • Kotlin was developed by JetBrains.
  • Kotlin is a functional, static type, Object-oriented, Procedural programming language. So, it removes lots of boiler plate.

2) What does ‘Null Safety’ mean in Kotlin?

  • Removing the risk of occurrence of NullPointerException.

3) Is there any Ternary Conditional Operator in Kotlin like in Java?

  • No ternary operator.

4) How many constructors are available in Kotlin?

  • Primary constructor: Header of the class is declared after the class name.
  • Secondary constructor: Declared in the body of the class.

5) Can you tell me what kinds of programming types does Kotlin support?

  • Procedural Programming
  • OOP

7) Explain the use of data class in Kotlin?

  • It contain basic data types.

8) Tell me the default behavior of Kotlin classes?

  • All classes are final by default.
  • Kotlin allows multiple inheritances for classes, and an open class is more expensive than a final class.

9) Does Kotlin support primitive Datatypes?

  • No

10) Why kotlin is better than Java?

  • Redundancy code when compared to java.
  • Kotlin support feature null safety, extension functions, primary constructors, inline or lamda expressions, properties and type interference for the properties and variables.

11) What are the high order functions?

  • High order functions consider functions as a parameter and produce a function.

12) How to convert a String into an int in the kotlin?

  • toint()

13) How to declare a variable in kotlin?

  • var and val

14) What is the difference between Val and var in the declaration of variables?

  • Val declaration we can not reassign the variables
  • Var reassign the variables of value.

15) List out the basic data types we use in kotlin?

  • Strings
  • Numbers
  • Arrays
  • Booleans
  • Characteristics

16) What are the structural expressions in kotlin?

  • Break
  • Return
  • Continue

17) What are the available modifiers in kotlin?

  • Public: By default, all the declarations are visible everywhere
  • Internal: This modifier helps to use declarations anywhere in the module.
  • Private: By this modifiers, the declarations are contained only in the file which is restricted.
  • Protected: In this, the declarations are secured, and not available for top-level declarations.

18) How many types of strings are available in kotlin?

  • Raw string
  • Escaped string

19) What is Elvis operator?

  • ? :
  • It is a variant of the ternary conditional operator but for null-safety checking.

20) What is the lateinit modifier used for?

  • lateinit modifier in Kotlin is used to delay the initialization of a variable.
  • These variables must be declared using var keyword, val is not allowed.
  • Must be either a property inside the body of a class or a top-level property
  • Can only be of non-null type
  • Primitive types disallowed.

21) Explain Launch vs Async in Kotlin?

  • Both Launch and async are coroutines in Kotlin.
  • Launch: It is used to fire and forget coroutine. It is like starting a new thread. If the code inside the launch terminates with an exception, then it is treated like an uncaught exception in a thread — usually printed to stderr in backend JVM applications and crashes Android applications.
  • Async: It is used to start a coroutine that computes some results. The result is represented by an instance of Deferred and you must use await on it. An uncaught exception inside the async code is stored inside the resulting Deferred and is not delivered anywhere else, it will get silently dropped unless processed.

22) What is inner class?

  • A inner class can access members of outer class. It carries a reference to an object of an outer class. Just like nested class, it is created inside an outer class and unlike a nested class, it is marked with the keyword inner. It has advantages over nested class is that, it can access private members of outer class.

23) Define Lambda Function?

  • A lambda function is a function that does not need to declare, but we can pass immediately as an expression. This is an anonymous function which is usually created during a function call to act as a function parameter.

24) What is the role of open keyword in Kotlin?

  • In Kotlin, by default, all the classes are final, means they cannot be inherited from. The open keyword is used to allow inheritance of a class.

25) What is nested class?

  • We can create one class within the body of another class. It is called nested class. A nested class cannot access the data member of an outer class. It is static by default. So we can access its properties and methods without instantiating this.

26) Differenciate between generics in and out?

  • The modifier in is used to apply contravariant type parameter, means to assign generic type as input to its function. The modifier out is used to apply covariance type parameter, means to assign a generic type as the output of its function.

27) Define enum?

  • Enum stands for enumeration, it is a special type of class. This is used to set some predefined constants. The enum keyword is used to create an enumeration class.

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in