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...


Explain the scope provided for variables in scala.



Explain the scope provided for variables in scala...

Answer / Gopal Prasad Poddar

In Scala, variables follow lexical (static) scoping rules. Variables can be defined inside blocks, functions, classes, objects, and packages. The scope of a variable extends to all parts of the program that are nested within the block where the variable is declared, including nested functions and classes. If a variable with the same name is redefined within a nested block or function, it hides the outer variable. For example, let's consider the following code snippet:nn```scalanval x = 10 // Global variablendef foo(): Unit = {n val x = 20 // Local variable in function foo()n println(x) // Prints 20n}nfoo()nprintln(x) // Prints 10n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

Compare to java what are the major advantages or benefits of scala?

1 Answers  


Like Hibernate for Java-based applications, What are the Popular ORM Frameworks available to use in Play/Scala based applications?

1 Answers  


Mention the types of variables in scala?

1 Answers  


What is the major change or update in Scala 2.12?

1 Answers  


What is the best Scala style checker tool available for Play and Scala based applications?

1 Answers  


Explain the use of tuples in scala?

1 Answers  


What is the difference between Function and Method in Scala?

1 Answers  


What is the difference between :: and #:: in Scala? What is the difference between ::: and #::: in Scala?

1 Answers  


What does sortedset in scala collection?

1 Answers  


Difference between Array and List in Scala?

1 Answers  


What do you mean by scala map?

1 Answers  


What is the best tool to develop Play/Scala applications to persist data in MongoDB NoSQL data store?

1 Answers  


Categories