Page 101 - CITS - CSA - TP (Volume 2) - Hindi
P. 101
कं ूटर सॉ वेयर ए ीके शन - CITS
Student student1 = new Student(“Alice”, 20, 85.5);
// Accessing object properties and methods
student1.displayInfo();
}
}
आउटपुट:
ीकरण:
• यह ो ाम नाम, आयु और ेड जैसे गुणों के साथ एक ू ड ट ास को प रभािषत करता है।
• इसम इं स वै रएबल को इिनिशयलाइज़ करने के िलए एक कं र है।
• displayInfo() िविध छा की जानकारी ि ंट करती है।
• main() िविध म , Student वग का एक ऑ े student1 बनाया जाता है, और इसके गुणों को displayInfo() िविध का उपयोग करके ए ेस
िकया जाता है।
टा 3: ब क अकाउंट ास
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 - कं ूटर सॉ वेयर ए ीके शन - अ ास 94

