Custom Search

Monday, 27 August 2012

Java Program to find area of Rectangle & circle using Abstract Class, Write a program in java explaining program Abstract Class, class modifiers


Java Program to find area of Rectangle & circle using Abstract Class, Write a program in java explaining program Abstract Class, class modifiers 


Program
/*  This is a example of Abstract  Class */
abstract class shape
{
double area;
final double PHI=22.0/7.0;
abstract double Area();
}
class Rectangle extends shape
{
double length,breadth;
Rectangle(double x,double y)
{
length=x;
breadth=y;
}
double Area()
{
area=length*breadth;
return area;
}
}
class Circle extends shape
{
double radious;
Circle(double r)
{
radious=r;
}
double Area()
{
area=PHI*radious*radious;
return area;
}
}
class Abscls
{
public static void main(String args[])
{
Rectangle rec=new Rectangle (6.0,4.0);
double ar;
ar=rec.Area();
System.out.println("Area of Ractangle is:"+ar);
Circle cir = new Circle(5.25);
ar=cir.Area();
System.out.println("Area of Circle is:"+ar);
}
}

No comments:

Post a Comment

Laptops