Home »
Scala
Comments in Scala
By IncludeHelp Last updated : October 07, 2024
Scala Comments
Comments are a very important part of programming. In Scala comments are Java-like. Comments are things that are readable by the programmer. They are added to the code to add an explanation about the source code. Commenting on a program to make it easier to understand by the programmer.
In Scala also comments are available. The comments in Scala are same as C++, Java and many other popular programming languages.
Types of Scala Comments
There are two types of comments that can be added to a program:
- Single Line Comments
- Multi Line Comments
1) Single Line Comments in Scala
It is the comment that has a span of an only single line. The line in which comment is started is commented.
Syntax
// Single line code to be commented...
2) Multi Line Comments in Scala
A multiline comment can span up to many lines based on its end literal. A multiline comment starts and ends with a literal and all the code inside that literal is treated as a comment.
Syntax
/*
Multiline
Code to be commented
*/
Example: Scala program to demonstrate single and multi line comments
object MyClass {
def main(args: Array[String]) {
//printing Hello world! - this is single line comment
print("Hello world!");
/*
This is multiline comment -
Here, we are printing Hi friends!
*/
print("Hi friends!");
}
}
Output
Hello world!Hi friends!