Page 41 - CTS - CSA TP - Volume 2
        P. 41
     COMPUTER SOFTWARE APPLICATION - CITS
                   // Set values to instance variables
                   myStudent.name = “Alice”;
                   myStudent.age = 20;
                   // Display student information
                   myStudent.displayStudentInfo();
               }
           }
           class Student {
               // Instance variables: name and age
               String name;
               int age;
               // Instance method to display student information
               void displayStudentInfo() {
                   System.out.println(“Name: “ + name);
                   System.out.println(“Age: “ + age);
               }
           }
           Output:
           TASK 3: Class Variables Examples
           public class VariableExample3 {
               public static void main(String[] args) {
                   // Access the class variable directly
                   System.out.println(“Default Interest Rate: “ + Bank.defaultInterestRate);
                   // Change the class variable
                   Bank.defaultInterestRate = 3.5;
             // Access the class variable through an instance
                   Bank myBank = new Bank();
                   System.out.println(“Updated Interest Rate: “ + myBank.defaultInterestRate);
               }
           }
                                                           26
                                CITS : IT & ITES - Computer Software Application - Exercise 83





