Programming Tutorials

MultiLevel Inheritance sample in Java

By: Paawan Chaudhary in Java Tutorials on 2012-09-19  

This Java program implements the following Multi Level Inheritance:

Class: Account 
Cust_name , acc_no
                          
Class: Saving_Acc
Min_bal, saving_bal

Class:Acct_Details
Deposits, withdrawals

Program

import java.lang.*;
import java.io.*;
class Account
{
	String cust_name;
	int acc_no;
	Account(String a, int b)
	{
		cust_name=a;
		acc_no=b;
	}
	void display()
	{
		System.out.println ("Customer Name: "+cust_name);
		System.out.println ("Account No: "+acc_no);
	}
}
class Saving_Acc extends Account
{
	int min_bal,saving_bal;
	Saving_Acc(String a, int b, int c, int d)
	{
		super(a,b);
		min_bal=c;
		saving_bal=d;
	}
	void display()
	{
		super.display();
		System.out.println ("Minimum Balance: "+min_bal);
		System.out.println ("Saving Balance: "+saving_bal);
	}
}
class Acct_Details extends Saving_Acc
{
	int deposits, withdrawals;
	Acct_Details(String a, int b, int c, int d, int e, int f)
	{
		super(a,b,c,d);
		deposits=e;
		withdrawals=f;
	}
	void display()
	{
		super.display();
		System.out.println ("Deposit: "+deposits);
		System.out.println ("Withdrawals: "+withdrawals);
	}
}
class q9Multilevel
{
	public static void main(String args[])
	{
		Acct_Details A = new Acct_Details("Pa.one",666,1000,5000,500,9000);
		A.display();
	}
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)