Abstract and Final Class sample
Abstract Class:
===========
We cannot create object directly of abstract class, we must inherit the abstract class into another class, interface, then we can use the method contain in abstract class.
Another important condition we must use the method of abstract class in derived place.
import java.io.*;
abstract class pnr
{
public void pnr_calculate() throws IOException
{
int principle,num_month;
float rate_interest,si;
DataInputStream ds=new DataInputStream(System.in);
System.out.println("Enter Principle Amount");
principle=Integer.parseInt(ds.readLine());
principle=Integer.parseInt(ds.readLine());
System.out.println("Enter duration in Months");
num_month=Integer.parseInt(ds.readLine();
System.out.println("Enter Rate of interest in Percentage");
rate_interest=Float.parseFloat(ds.readLine());
si=(principle*num_months*rate_interest)/100;
System.out.println("Simple Interest rate is: "+si);
}
}
class sampleabstract extends pnr //Inherit abstract class
{
public static void main(String ss[]) throws IOException
{
pnr_calculate();
}
}
Final Class:
=========
we can create object for final class but cannot inherite any other class. That is final class is the last derived class for inheritance.
import java.io.*;
final class pnr
{
public void pnr_calculate() throws IOException
{
int principle,num_month;
float rate_interest,si;
DataInputStream ds=new DataInputStream(System.in);
System.out.println("Enter Principle Amount");
principle=Integer.parseInt(ds.readLine());
principle=Integer.parseInt(ds.readLine());
System.out.println("Enter duration in Months");
num_month=Integer.parseInt(ds.readLine();
System.out.println("Enter Rate of interest in Percentage");
rate_interest=Float.parseFloat(ds.readLine());
si=(principle*num_months*rate_interest)/100;
System.out.println("Simple Interest rate is: "+si);
}
}
class samplefinal
{
public static void main(String ss[]) throws IOException
{
pnr obj=new pnr();
obj.pnr_calculate();
}
}
Comments
Post a Comment