BCA Slip15 Java

Java

Slip15

Q1. Define an abstract class Shape with abstract methods area() and volume(). Write a java program to calculate area and volume of Cone and Cylinder. [Marks 30] 

Solution

import java.io.*;
abstract class Shape
{
  abstract void area();
  abstract void vol();
}

 class Cyl extends Shape
{
  float r,a,v,h;
  Cyl(float ra,float ha)
  {
    r=ra;
    h=ha;
  }
  void area()
  {
     a=2* 3.14f*r*(h+r);
     System.out.println("Area OF Cyl is \t" +a);
  }
  void vol()
  {
    v= 3.14f * r*r*h;
    System.out.println("Volume Of Cyl Is \t" +v);
  }
}
class Cone extends Shape
{
  float r,a,v,l,h;
  Cone(float ra,float ha,float la)
  {
    r=ra;
    l=la;
    h=ha;
  }
  void area()
  {
     a= 3.14f*r*(l+r);
     System.out.println("Area OF Cone is \t" +a);
  }
  void vol()
  {
    v=(3.14f * r*r*h)/3;
    System.out.println("Volume Of Cone Is \t" +v);
  }
}
class Assgn15
{
  public static void main(String args[]) throws Exception
  {
    Shape s;

    Cyl cp=new Cyl( 5.2f,3.2f);
    s = cp;
    s.area();
    s.vol();
    Cone co=new Cone(2.3f,1.2f, 5.2f);
    s = co;
    s.area();
    s.vol();
  }
}

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post