Write a java program to create an Account class and define constructors in it. Inherit Saving_Bank_Account class and Current_Bank_Account class from the Account class. Override constructors of Account class in Saving_Bank_Account and Current_Bank_Account classes. Define appropriate methods to operate these accounts. Make necessary assumptions. Give proper comment in your program to increase redability.
public class Main
{
public static void main(String[] args) {
Saving_Bank_Account s=new Saving_Bank_Account(123, 10600.00);
Current_Bank_Account c=new Current_Bank_Account(456, 2300.50);
s.print2();
c.print3();
}
}
class Account{
private int account_number;
public Account(int a){
account_number=a;
}
public void print1(){
System.out.println("Account number is: "+account_number);
}
}
class Saving_Bank_Account extends Account{
private double amount;
public Saving_Bank_Account(int a, double amt){
super(a);
amount=amt;
}
public void print2(){
print1();
System.out.println("Amount in saving bank account_number: "+amount);
}
}
class Current_Bank_Account extends Account{
private double amount;
public Current_Bank_Account(int a, double amt){
super(a);
amount=amt;
}
public void print3(){
print1();
System.out.println("Amount in current bank account: "+amount);
}
}
Comments
Leave a comment