Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the difference between const vs val?



What is the difference between const vs val?..

Answer / Krishan Kant Sharma

In Kotlin, both 'const' and 'val' are used to declare constants. However, there is a significant difference between the two.nnVal is a constant variable that can be reassigned within its declaration if it is an object or a function reference. On the other hand, const is a compile-time constant, which means it cannot be reassigned at all, even if it's not an object or a function reference.nnFor example,nnval PI: Double = 3.14nncan be rewritten as:nnconst val PI: Double = 3.14nBut the following code will result in a compile-time error if PI is declared as const:nnconst val MY_OBJECT = SomeClass()nMY_OBJECT = AnotherClass()

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Kotlin Interview Questions

How are Primary Constructors different from Secondary Constructors ?

1 Answers  


What does "Null Safety" mean in Kotlin?

1 Answers  


What are the features of java has that kotlin does not?

1 Answers  


Why you should shift from Java to kotlin?

1 Answers  


What is the difference between Return Type Unit and Return Type Nothing in Kotlin?

1 Answers  


Why do we need write open before class name in Kotlin while working on inheritance?

1 Answers  


How to make a class data class ?

1 Answers  


Tell me the default behavior of Kotlin classes?

1 Answers  


Who created Kotlin programming language and when?

1 Answers  


What is Ranges operator in Kotlin?

1 Answers  


How Kotlin works?

1 Answers  


Define String datatype with example in Kotlin?

1 Answers  


Categories