Labels

Monday, April 11, 2022

SCALA Basic Program (Class -24)

 There are 3 parts in Scala program-

a) Class definition,

b) Main() function and

c) Print statement.



object MyClass {

        def main(args: Array[String]) {

         print("Hello World!");

      }

   }

1) def keyword in Scala is used to declare (initialize) functions and methods.

2) main() tells the compiler that this method needs to be called first when the code is running.

3) args is the arguments which are passed by the user or programmer to the main() method are termed as Command-Line Arguments.

4) Array is a special kind of collection in scala. It is a fixed size data structure that stores elements of the same data type.

    The index of the first element of an array is zero and the last element is the total number of elements minus one.  It is a collection of mutable values.

5) String is an immutable object, that is, an object that cannot be modified.

 

6) print() method take a string value as input and prints it on screen.

 

A function takes some variables in its definition as arguments that are passed when it is called.

No comments:

Post a Comment