0 votes
in Scala Constructs by
What are different types of Identifiers in Scala?

1 Answer

0 votes
by
Identification is done with the help of identifiers in programming languages. The identifiers in Scala are case-sensitive and can be class, method, variable, or object name.

Example:  

class Madanswer

{

    var x: Int = 45

}

object Scaler

{

       def main(args: Array[String])  

           {

               var y = new Madanswer();

           }

}  

As you can see from the above example, we have six identifiers:  

Madanswer: Class name

x: Variable name

Scaler: Object name

main: Method name

args: Variable name

y: Object name

Types of Identifiers

Alphanumeric Identifiers: These identifiers start with a letter (capital/small) or underscore, followed by a digit, letter, or underscore.

Example: myVal , _Scaler , etc.

Operator Identifiers: These identifiers contain one or more operator characters (such as +, :, ?, ~, or #, etc.).

Example: +, ++ , etc.

Mixed Identifiers: This type of identifier consists of an alphanumeric identifier followed by an underscore and the operator identifier.

Example: scaler_+ , myVal_= , etc.

Literal Identifiers: In these identifiers, an arbitrary string is enclosed with backticks (`….`).

Example: `Scaler` , etc.
...