0% found this document useful (0 votes)
14 views2 pages

Abstract Class in Java

Write a program to display the volume of sphere and hemisphere using abstract class.

Uploaded by

Aman Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Abstract Class in Java

Write a program to display the volume of sphere and hemisphere using abstract class.

Uploaded by

Aman Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXP10:Write a program to display the volume of sphere and

hemisphere using abstract class.


Source code:
import java.util.*;

abstract class Volume{

public abstract double calculate(float r);

class Sphere extends Volume{

public double calculate(float r){

return (4.0/3.0)*Math.PI*r*r*r;

class HemiSphere extends Volume{

public double calculate(float r){

return (2.0/3.0)*Math.PI*r*r*r;

public class AbstractImplement {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

Sphere sphere = new Sphere();

HemiSphere hemisphere = new HemiSphere();

float radius;

System.out.println("Enter radius of Sphere: ");


radius = s.nextFloat();

System.out.println("Volume of Sphere: " + sphere.calculate(radius));

System.out.println("\nEnter radius of Hemi Sphere: ");

radius = s.nextFloat();

System.out.println("Volume of Hemisphere: " + hemisphere.calculate(radius));

OUTPUT:

You might also like