ISC Practicals and Theory - Plane to Circle/Cylinder
Updated 21 Oct 2026
A cylinder has a circle as its base, so it is natural to write a base class Plane for the circle (its radius and area) and a derived class Cylinder that adds a height and uses the inherited radius and area to find the volume and the surface areas. This is the standard form of the program: default constructors, an accept() and a display() in each class, and the derived class calling the base class methods with super.
Definition
Inheritance lets a derived class (class Cylinder extends Plane) use the data members and methods of the base class and add its own. Data members marked protected can be used directly in the derived class. A method written again in the derived class with the same name and parameters is redefined (overridden), and super.method() calls the base class version.
For a circle of radius $r$ and a cylinder of height $h$:
- area of the circle $= \pi r^2$
- volume $= \pi r^2 h$ (base area $\times$ height)
- curved surface area $= 2 \pi r h$
- total surface area $= 2 \pi r h + 2 \pi r^2$ (curved area plus two circular ends)
The program uses $\pi = 3.14159$ as a constant.
For example, $r = 3$ and $h = 5$: base area $= 28.27431$, volume $= 141.37155$, curved area $= 94.2477$, total area $= 94.2477 + 2 \times 28.27431 = 150.79632$.
Both radius and height must be greater than 0; otherwise the program prints INVALID INPUT.
Algorithm
main(in the driver classTest) creates an objectobof the derived classCylinder. The constructorCylinder()setsheightto 0, afterPlane()has setradiusto 0.maincallsob.accept(), theaccept()ofCylinder:- it first calls
super.accept(), theaccept()ofPlane, which readsradiusand returnsfalseif it is 0 or less; - if that returned
false,Cylinder'saccept()returnsfalseat once; - otherwise it reads
heightand returnsfalseif it is 0 or less, elsetrue.
- it first calls
- If
accept()returnedfalse,mainprintsINVALID INPUTand stops. - Otherwise
maincallsob.display(), thedisplay()ofCylinder. It callssuper.display(), which prints the radius and the base area fromarea()(PI * radius * radius), then prints:- the height;
volume(), which returnsarea() * height, reusing the inherited method;curvedArea(), which returns2 * PI * radius * height;totalArea(), which returnscurvedArea() + 2 * area().
- Every result is printed to 2 decimal places with
printf("%.2f").
Program
Plane holds the radius and the circle's area, Cylinder adds the height and the three cylinder results, and Test only holds main. The Scanner is a static member of Plane, so both classes read from the same one.
import java.util.Scanner;
/* Base class: a plane figure, the circle, described by its radius. */
class Plane
{
protected double radius; // radius of the circle
protected final double PI = 3.14159; // value of pi used in all formulae
static Scanner sc = new Scanner(System.in); // one Scanner shared by Plane and Cylinder
/* Default constructor: radius starts at 0. */
Plane()
{
radius = 0.0;
}
/* Reads the radius. Returns true if it is greater than 0, otherwise false. */
boolean accept()
{
System.out.print("Enter radius: ");
radius = sc.nextDouble();
if (radius <= 0)
{
return false;
}
return true;
}
/* Returns the area of the circle: PI * r * r. */
double area()
{
return PI * radius * radius;
}
/* Prints the radius and the area of the circle. */
void display()
{
System.out.printf("Radius : %.2f%n", radius);
System.out.printf("Area of the base : %.2f%n", area());
}
}
/* Derived class: a cylinder, a Plane (its base) with a height. */
class Cylinder extends Plane
{
double height; // height of the cylinder
/* Default constructor: height starts at 0. */
Cylinder()
{
height = 0.0;
}
/* Reads the radius through the base class and then the height.
Returns true only if both are greater than 0. */
boolean accept()
{
if (!super.accept()) // stop at once if the radius was invalid
{
return false;
}
System.out.print("Enter height: ");
height = sc.nextDouble();
if (height <= 0)
{
return false;
}
return true;
}
/* Returns the volume: base area * height (area() is inherited). */
double volume()
{
return area() * height;
}
/* Returns the curved surface area: 2 * PI * r * h. */
double curvedArea()
{
return 2 * PI * radius * height;
}
/* Returns the total surface area: curved area + two circular ends. */
double totalArea()
{
return curvedArea() + 2 * area();
}
/* Prints the base details through the base class, then the cylinder's results. */
void display()
{
super.display();
System.out.printf("Height : %.2f%n", height);
System.out.printf("Volume : %.2f%n", volume());
System.out.printf("Curved surface area: %.2f%n", curvedArea());
System.out.printf("Total surface area : %.2f%n", totalArea());
}
}
/* Driver class: holds main. */
public class Test
{
/* Creates one Cylinder object and runs accept and display. */
public static void main(String args[])
{
Cylinder ob = new Cylinder(); // object of the derived class
if (ob.accept())
{
ob.display();
}
else
{
System.out.println("INVALID INPUT");
}
}
}Variable description table
| Variable | Data Type | Purpose |
|---|---|---|
radius | double | Protected data member of Plane: radius of the circle and of the cylinder's base |
PI | double | Protected constant of Plane: value of pi (3.14159) |
sc | Scanner | Static data member of Plane: reads all the input |
height | double | Data member of Cylinder: height of the cylinder |
ob | Cylinder | Object of the derived class created in main |
args | String[] | Command-line arguments of main (not used) |
Sample input and output
Sample 1
Enter radius: 3
Enter height: 5
Radius : 3.00
Area of the base : 28.27
Height : 5.00
Volume : 141.37
Curved surface area: 94.25
Total surface area : 150.80Sample 2
Enter radius: 0.1
Enter height: 0.2
Radius : 0.10
Area of the base : 0.03
Height : 0.20
Volume : 0.01
Curved surface area: 0.13
Total surface area : 0.19Sample 3
Enter radius: 2.5
Enter height: 10
Radius : 2.50
Area of the base : 19.63
Height : 10.00
Volume : 196.35
Curved surface area: 157.08
Total surface area : 196.35Sample 4
Enter radius: 4
Enter height: -2
INVALID INPUTDry run
Take the first sample: radius $= 3$, height $= 5$. After accept(), radius is 3.0 and height is 5.0. display() works out:
| Step | Statement | Value |
|---|---|---|
| 1 | area(): 3.14159 * 3 * 3 | 28.27431 |
| 2 | volume(): area() * 5 | 141.37155 |
| 3 | curvedArea(): 2 * 3.14159 * 3 * 5 | 94.2477 |
| 4 | totalArea(): 94.2477 + 2 * 28.27431 | 150.79632 |
Printed to 2 decimal places these are 28.27, 141.37, 94.25 and 150.80, so the last line is Total surface area : 150.80, as in the first sample run.
Variations
- Cone "Write a base class for a circle and a derived class for a cone that finds its volume, curved surface area and total surface area."
- Sphere "Derive a class for a sphere from the circle class and find its volume and surface area."
- Different base "Write a class for a rectangle and a derived class for a cuboid that finds its volume and total surface area."