Page 40 - CITS - CSA - TP (Volume 2) - Hindi
P. 40
कं ूटर सॉ वेयर ए ीके शन - 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);
}
}
आउटपुट:
टा 3: ास वे रएब उदाहरण
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 - कं ूटर सॉ वेयर ए ीके शन - अ ास 83

