Friday, February 4, 2011

inner class

//on Inner class

import java.io.*;
class BankAct
{
private double bal;
BankAct(double b)
{
bal=b;
}

void start(double r)
{
Intrest in=new Intrest(r);
in.calintrest(); //calling Inner class method
}


private class Intrest
{
private double rate;

Intrest(double r)
{
rate=r;
}

void calintrest()
{
double intrest=bal*rate/100;
System.out.println("Intrest--"+intrest);
bal+=intrest;
System.out.println("Bal=----"+bal);
}
}
}

class Innerclass
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter balance");
int b=Integer.parseInt(br.readLine());

BankAct account=new BankAct(b);

System.out.println("enter intrest");
int i=Integer.parseInt(br.readLine());

account.start(i);
}
}

No comments:

Post a Comment