Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

EXPERIMENT NO.

7
AIM : ABSTRACT CLASS
NAME : Jesiya Johny Fernandes CLASS : SE (COMP)
BATCH:C3 ROLL NO : 76
1. Abstract Class :
import java.util.*;
abstract class Solid
{
double radius; // Abstract methods public abstract void readRadius();
public abstract void volume(); public abstract void surfaceArea();
// Abstract method for base area
public abstract double baseArea();
}
class Cone extends Solid { double height;
// Default constructor Cone()
{
height = 0;
}
Cone(double height)
{
this.height = height;
}
public void readRadius()
{
Scanner sc = new Scanner(System.in); System.out.print("Enter the radius of the cone: "); radius =
sc.nextDouble();
}
public void volume()
{
double volume = (1.0 / 3.0) * Math.PI * radius * radius * height;
System.out.println("Volume of cone = " + volume);
}
public void surfaceArea()
{
double slantHeight = Math.sqrt(radius * radius + height * height); double area = Math.PI * radius * (radius
+ slantHeight);
System.out.println("Surface area of cone = " + area);
}
public double baseArea()
{
double baseArea = Math.PI * radius * radius; System.out.println("Base area of cone = " + baseArea);
return baseArea;
}
}
class SolidDemo
{
public static void main(String args[])
{
Cone c = new Cone(10); c.readRadius();
c.volume();
c.surfaceArea();
c.baseArea();
}
}

/*OUTPUT
D:\ OOPSLAB >java SolidDemo
Enter the radius of the cone: 5
Volume of cone = 261.79938779914943
Surface area of cone = 254.160184615763
Base area of cone = 78.53981633974483
*/

You might also like