Page 104 - CTS - CSA TP - Volume 2
P. 104
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• This program defines a BankAccount class with properties like account number and balance.
• It has a constructor to initialize the instance variables.
• The deposit() method deposits money into the account, withdraw() method withdraws money, and
displayAccountInfo() method displays the account information.
• In the main() method, an object account1 of the BankAccount class is created and operations like deposit,
withdraw, and display account information are performed.
These examples demonstrate how classes, objects, and methods are used in Java to model real-world entities
and perform operations on them. They encapsulate data and behavior within classes, promoting code reusability
and maintainability.
TASK 4: Car Class
class Car {
// Instance variables
String make;
String model;
int year;
// Constructor
Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
// Method to display car information
void displayInfo() {
System.out.println(“Make: “ + make);
System.out.println(“Model: “ + model);
System.out.println(“Year: “ + year);
}
}
public class CarDemo {
public static void main(String[] args) {
// Create an object of Car class
Car myCar = new Car(“Toyota”, “Camry”, 2020);
// Accessing object properties and methods
myCar.displayInfo();
}
}
89
CITS : IT & ITES - Computer Software Application - Exercise 94