Abstract Classes Java

This Simple Java Program is for performing Abstract classes in Java. This is a part of Mumbai University MCA Colleges Java Practicals.

Abstract Classes Contains Abstract Methods as well as hardcore methods (Methods which are predefined).  Abstract classes are extended or inherited.

In the Below program Abstract Class named Interest is used by 2 classes named SimpleInterest and CompoundInterest. These 2 classes uses the variables, Constructor and the display method of the abstract class. Both the classes use different definitions for the abstract method calc() to calculate the interest.

abstract class Interest
{
double p,amt,n;
Interest(double a,double y)
{
p=a;
n=y;
}
void display()
{
System.out.println("\nAMOUNT = "+p+"\nNOS OF YRS ="+n);
}
abstract void calc();
}

class SimpleInterest extends Interest
{
SimpleInterest(double a,double y)
{
super(a,y);
}
void calc()
{
amt= (p*n*0.0925);
System.out.println("SIMPLE INTEREST="+amt);
}
}

class CompoundInterest extends Interest
{
CompoundInterest(double a,double y)
{
super(a,y);
}
void calc()
{
amt= p*Math.pow((1+(8.5/100)),n);
System.out.println("COMPOUND INTEREST="+amt);
}
}

class Bank
{
public static void main(String str[])
{
Interest i;
SimpleInterest s1=new SimpleInterest(25000,5);
CompoundInterest c1=new CompoundInterest(25000,5);
i=s1;
i.display();
i.calc();
i=c1;
i.display();
i.calc();
}
}


Hope this Java Program is useful to you in some sense or other. Keep following this blog for more Mumbai University MCA College Programs and simple Programs. Happy Programming and Studying

No comments:

Post a Comment