1.

What are different types of Identifiers in Scala?

Answer»

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 InterviewBit { var x: Int = 45 } object Scaler { def main(args: Array[String]) { var y = NEW InterviewBit(); } }

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

  • InterviewBit: 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.


Discussion

No Comment Found