Answer to Question #15673 in C# for Zulekha

Question #15673
Define an abstract class ‘Bank’ having abstract methods as‘CreateAccount’ ‘depositAmount’ and ‘withDrawAmount’.Add methoddefinitions for ‘CalculateInterest’ and ‘SetIntereset’ as Non-Overridable.Define two classes ‘BharatiBank’ and ‘RupeeBank’ to derivefrom bank class.In main ,method create objects of BharatiBank’ andRupeeBank’ to represent Bank type and call their respective methods.Can Bank type call the derived classes own methods that re not defined inbank ?
1
Expert's answer
2012-10-02T07:39:07-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

abstract class Bank
{
& public abstract& void CreateAccount();
& public abstract void depositAmount();
& public abstract& void withDrawAmount();
& public abstract& void CalculateInterest();
& public abstract& void SetIntereset();
}
class BharatiBank : Bank
{
& public override void depositAmount()
& {
throw new Exception("The method or operation is not implemented.");
& }

& public override void withDrawAmount()
& {
throw new Exception("The method or operation is not implemented.");
& }

& public override void CalculateInterest()
& {
Console.WriteLine("Calculate Bharati bank");
& }

& public override void SetIntereset()
& {
Console.WriteLine("Set Bharati bank");
& }

& public override void CreateAccount()
& {
throw new Exception("The method or operation is not implemented.");
& }
}
class RuppeBank : Bank
{
& public override void depositAmount()
& {
throw new Exception("The method or operation is not implemented.");
& }

& public override void withDrawAmount()
& {
throw new Exception("The method or operation is not implemented.");
& }

& public override void CalculateInterest()
& {
Console.WriteLine("Calculate Ruppe bank");
& }

& public override void SetIntereset()
& {
Console.WriteLine("Set Ruppe bank");
& }

& public override void CreateAccount()
& {
throw new Exception("The method or operation is not implemented.");
& }
}




&



class Program
{
& static void Main(string[] args)
& {
RuppeBank RB = new RuppeBank();
BharatiBank BB = new BharatiBank();
RB.CalculateInterest();
BB.CalculateInterest();
RB.SetIntereset();
BB.SetIntereset();


& }
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS