Home »
Scala
Scala Keywords
By IncludeHelp Last updated : October 07, 2024
Keywords
Keywords are also known as reserved words, keywords are special words for a programming language that have some predefined actions in the programming. Thus, these keywords cannot be used as names for defining objects, classes, functions, variables, etc. The compiler will throw an error if we try to use keywords as identifiers.
List of Scala Keywords
Scala programming languages also consist of a set of keywords to help in the efficient working of the program.
There are in total 39 keywords present in Scala. Here is a list of all keywords in Scala,
- 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
- try
- true
- type
- val
- var
- while
- with
- yield
Other than data types are also reserved in Scala.
Scala Keyword Example
This example illustrates the use of keyword as identifier (This will return an error)
Scala example to use keyword as an identifier
object MyClass {
def main(args: Array[String]) {
val class = 315.12
val score = class*100 / 500
println("My Score is " + score + "%")
}
}
Output
scala:3: error: illegal start of simple pattern
val class = 315.12
^
scala:4: error: '=' expected.
val score = class*100 / 500
^
scala:4: error: illegal start of simple expression
val score = class*100 / 500
^
Scala Keywords Related Questions
How many keywords are there in Scala?
There is total 39 keywords are there in Scala.
Is type a keyword in Scala?
Yes, type is a keyword in Scala.
Is static a keyword in Scala?
No, static is not a keyword in Scala.
Does Scala have a public keyword?
No, Scala doesn't have a public keyword