Page 74 - Viva ICSE Computer Studies 8 : E-book
P. 74

Assignment Operators

                    Assignment operator is used to assign a value to a variable or a constant. Variables are on the
                    left hand side of the assignment operator and value to be assigned is on the right hand side of
                    the assignment operator.
                      •  +=  :   It is used to increase the variable on the left by an arbitrary value on the right, for
                                example a = a + 1.
                      •  −=  :   It is used to decrease the variable on the left by an arbitrary value on the right, for
                                example a = a − 1.

                      •  *=  :   It is used to multiply the variable on the left by an arbitrary value on the right, for
                                example a = a   3.
                                                *
                      •  /=  :   It is used to divide the variable on the left by an arbitrary value on the right, for
                                example a = a / 9.
                      •  %= :   It is used to divide the variable on the left by an arbitrary value on the right. It
                                stores the remainder, for example a = a % 9.

                    You can use diff erent types of operators in an expression, but their order of precedence follows
                    the BEDMAS (Brackets, Exponents, Division, Multiplication, Addition and Subtraction) rule.

                    Class Declaration

                    Let’s understand class declaration with an example.

                    Public class Student
                    {

                    Public String name;
                    Public int rollno;

                    Public void display()
                    {

                    System.out.println(“Name is” +name);
                    System.out.println(“Rollno is”+rollno);

                    }
                    }

                      •  Here, ‘Public’ is the access specifi er that means it can be accessed by anyone. ’Student’ is
                          the name of the class, preceded by the keyword class.
                      •  The body of the class begins with a left brace ’{‘.
                      •  Name and rollno are two variables of ‘string’ and ‘int’ data type.

                      •  Display() is a method name with access specifi er as public which means that it can be
                          accessed by anyone and return type as ‘void’ which means that the method will not
                          return any value except the text that we enter in the Print statements.
                      •  Body of the function defi ned in the pair of braces ’{}’.
                      •  The class ends with a right brace ‘}’.



                     62
   69   70   71   72   73   74   75   76   77   78   79