Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as variable names or objects. Doing this will result in a compile-time error.
Example:
// Scala Program to illustrate the keywords // Here object, def, and var are valid keywords object Main { def main(args: Array[String]) { var p = 10 var q = 30 var sum = p + q println("The sum of p and q is :"+sum); } } |
chevron_right
filter_none
Output:
The sum of p and q is :40
Scala contains following keywords:
| abstract |
| case |
| catch |
| class |
| def |
| do |
| else |
| extends |
| false |
| final |
| finally |
| for |
| forSome |
| if |
| implicit |
| import |
| lazy |
| match |
| new |
| null |
| object |
| override |
| package |
| private |
| protected |
| return |
| sealed |
| super |
| this |
| throw |
| trait |
| true |
| try |
| type |
| val |
| var |
| while |
| with |
| yield |
| >: |
| ⇒ |
| => |
| = |
| <% |
| <: |
| ← |
| <- |
| # |
| @ |
| : |
| _ |
Example:
// Scala Program to illustrate the keywords // Here class keyword is used to create a new class // def keyword is used to create Function // var keyword is used to create a variable class GFG { var name = "Priyanka" var age = 20 var branch = "Computer Science" def show() { println("Hello! my name is " + name + "and my age is"+age); println("My branch name is " + branch); } } // object keyword is used to define // an object new keyword is used to // create an object of the given class object Main { def main(args: Array[String]) { var ob = new GFG(); ob.show(); } } |
chevron_right
filter_none
Output:
Hello! my name is Priyankaand my age is20 My branch name is Computer Science
Recommended Posts:
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala short <(x: Short): Boolean
- Scala short <(x: Char): Boolean
- Scala Extractors
- Scala | Partially Applied functions
- Scala String indexOf(String str) method with example
- Scala String contentEquals() method with example
- Scala Int /(x: Int) method with example
- Scala Int /(x: Short) method with example
- Program to print Java Set of characters in Scala
- Scala Map size() method with example
- Scala SortedMap addString() method with a start, a separator and an end with example
- Scala Iterator addString() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala | Functions Call-by-Name
- Program to convert Java list to an iterator in Scala
- Scala Set &() method with example
- Scala | Type Inference
- Program to convert Java set of Shorts to an Indexed Sequence in Scala
- Scala Int <(x: Char) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

