What is a const? How does it differ from a val?
Answer / Mamta Sonkar
A 'const' in Kotlin is a constant value that must be initialized at compile-time. It cannot be reassigned even if the variable is not an object or a function reference.nnOn the other hand, a 'val' is a constant variable that can be reassigned within its declaration if it is an object or a function reference.nnFor example:nnconst val PI: Double = 3.14nval MY_OBJECT: SomeClass? = nullnMY_OBJECT = AnotherClass() // Valid for val, but not for const
| Is This Answer Correct ? | 0 Yes | 0 No |
Who created Kotlin programming language and when?
What is the equivalent of switch expression in Kotlin? How does it differ from switch?
How is kotlin integrated with Gradle?
What is Kotlin?
What is the extension of Kotlin file?
How are Primary Constructors different from Secondary Constructors ?
How to convert a String to an Integer?
How do you migrate the code from Java to Kotlin ?
Can you tell me what kinds of programming types does Kotlin support?
What are the major features of Kotlin?
How does interoperable feature work in Kotlin for java ?
Is there any disadvantage of Kotlin ?