Example for understanding class object and method

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1179

Program:

 // Save it as File name : MainClassOfAccount.java
// Example for understanding class object and method

class Account_class{
int account_no;
String name;
float amount;
void insert(int a,String n,float amt){
account_no=a;
name=n;
amount=amt;
}
void deposit(float amt){
amount=amount+amt;
System.out.println(amt+" deposited");
}
void withdraw(float amt){
if(amount < amt){
System.out.println("Insufficient Balance");
}else{
amount=amount-amt;
System.out.println(amt+" withdrawn");
}
}
void checkBalance(){System.out.println("Balance is: "+amount);}
void display(){System.out.println(account_no+" "+name+" "+amount);}
}


class MainClassOfAccount{
public static void main(String[] args){
Account_class a1=new Account_class();
a1.insert(1212,"Romen",1200);
a1.display();
a1.checkBalance();
a1.deposit(50000);
a1.checkBalance();
a1.withdraw(34000);
a1.checkBalance();
}}

Output:

1212 Romen 1200.0
Balance is: 1200.0
50000.0 deposited
Balance is: 51200.0
34000.0 withdrawn
Balance is: 17200.0
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.