Page 40 - CTS - CSA TP - Volume 2
        P. 40
     COMPUTER SOFTWARE APPLICATION - CITS
           EXERCISE 83 : Create and use Local, Instance and Class
                                     variables
            Objectives
           At the end of this exercise you shall be able to
           •  know the use of various Local, Instance and Class variables
           •  develop  Java Programs  using different Local, Instance and Class variables
           •  compile , Execute and verify the result of the Java Programs.
           Requirements
           Tools/Materials
           •  PC/Laptop  with Windows OS
           •  JDK Software
            Procedure
           Text Editor (Visual Studio/Sublime/Notepad)
           TASK  1 :  Local Variables Example
           public class VariableExample1 {
            public static void main(String[] args) {
                   calculateSum(5, 7);
               }
               static void calculateSum(int a, int b) {
                   // Local variable: sum
                   int sum = a + b;
                   System.out.println(“Sum: “ + sum);
               }
           }
           Output:
           TASK 2: Instance Variables Example
           public class VariableExample2 {
               public static void main(String[] args) {
                   // Create an instance of the Student class
                   Student myStudent = new Student();
                                                           25
 CITS : IT & ITES - Computer Software Application - Exercise 82





