Page 102 - CTS - CSA TP - Volume 2
P. 102
COMPUTER SOFTWARE APPLICATION - CITS
Student student1 = new Student(“Alice”, 20, 85.5);
// Accessing object properties and methods
student1.displayInfo();
}
}
Output:
Explanation:
• This program defines a Student class with properties like name, age, and grade.
• It has a constructor to initialize the instance variables.
• The displayInfo() method prints out the student’s information.
• In the main() method, an object student1 of the Student class is created and its properties are accessed using
the displayInfo() method.
TASK 3: Bank Account Class
class BankAccount {
// Instance variables
String accountNumber;
double balance;
// Constructor
BankAccount(String accNum, double initialBalance) {
accountNumber = accNum;
balance = initialBalance;
}
// Method to deposit money
void deposit(double amount) {
balance += amount;
System.out.println(amount + “ deposited successfully.”);
}
// Method to withdraw money
void withdraw(double amount) {
87
CITS : IT & ITES - Computer Software Application - Exercise 94