-
-
Save pradhuman7d1/9d0c37b250f2531ff79b64d80f1ca1cb to your computer and use it in GitHub Desktop.
Kotlin Introduction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. What are mutable and immutable variables? | |
A. Mutable variables are the ones that can be modified and reassigned, but immutable variables can't be edited after one assignment. | |
Q. What is the difference between val and var? | |
A. var keyword is for creating mutable variables and val is for creating immutable variables. | |
Q. What is explicit type declaration? | |
A. Defining the type of a variable while declaration is explicit type declaration. eg: var a : Int = 10 | |
Q. What is type casting? | |
A. Converting one type of variable to another. | |
Q. What is the difference between print() and println()? | |
A. print() only prints the statement whereas println() prints the statement and then shifts the cursor to next line. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. Which of the following is the correct syntax for variable declaration in Kotlin? | |
a) var a : Int = 4 | |
b) Int var a = 2 | |
c) int val a = 200 | |
d) var a Int = 1 | |
A. a) var a : Int = 4 | |
Q. What will be the output of this snippet on console ? | |
fun main(args : Array<String>) { | |
val a : Int = "PEP" | |
println(a) | |
a = "PEPCODING" | |
println(a) | |
} | |
a) PEP | |
b) PEPCODING | |
c) compilation error | |
d) PEP in first line than PEPCODING in next | |
A. c) compilation error | |
Q. How to assign the max possible value of a datatype to a variable in Kotlin? | |
a) var a : Int = a.MAX_VALUE | |
b) var a : Int = MAX.Int | |
c) var a : Int = Int.MAX_VALUE | |
d) var a : Int = MAX.a | |
A. c) var a : Int = Int.MAX_VALUE | |
Q. What is the size of a Long variable? | |
a) 8 bits | |
b) 16 bits | |
c) 32 bits | |
d) 64 bits | |
A. d) 64 bits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment