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:
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:
Output:
Hello! my name is Priyankaand my age is20
My branch name is Computer Science