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

What is Range in Kotlin?

1 Answers  


Can kotlin code be executed without jvm?

1 Answers  


Describe the use of extension function?

1 Answers  


Name the extension methods Kotlin provides to java.io.File?

1 Answers  


What is Kotlin Native?

1 Answers  


What are Data classes ? Aren’t they available in Java ?

0 Answers  


What are the features available in kotlin but not in java?

1 Answers  


Why is Kotlin interoperable with Java?

1 Answers  


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

1 Answers  


What are the different types of constructors in Kotlin?

1 Answers  


Explain functions in kotlin?

1 Answers  


Where does the Kotlin run and what is the entry point of Kotlin?

1 Answers  


Categories