Class 12

ISC 2020 Computer Science Theory Data Interface Program

An interface Data is defined with a data member and a method volume() which returns the volume of the implementing shape. A super class Base has been defined to contain the radius of a geometrical shape. Define a sub-class CalVol which uses the properties of the interface Data and the class Base and calculates the volume of a cylinder.

The details of the members of the interface and both the classes are given below:

Interface name: Data
Data member:
double pi: initialize pi = 3.142.
Member function/method:
double volume()

Class name: Base
Data member/instance variable:
rad: to store the radius in decimal.
Member functions/methods:
Base(…): parameterized constructor to initialize the data members.
void show(): displays the radius with an appropriate message.

Class name: CalVol
Data member/instance variable:
ht: to store the height in decimal.
Member functions/methods:
CalVol(…): parameterized constructor to initialize the data members of both the classes.
double volume(): calculates the volume of a sphere by using the formula (pi × radius2 × height)
void show(): displays the data members of both the classes and the volume of the sphere with appropriate message.

Assume that the interface Data and the super class Base has been defined. Using the concept of inheritance, specify the class CalVol giving details of the constructor, double volume() and void show().

The interface, super class, main() function and algorithm need not be written.

interface Data{
    final double pi = 3.142;
    double volume();
class Base{
    double rad;
    public Base(double r){
        rad = r;
    public void show(){
        System.out.println("Radius: " + rad);
class CalVol extends Base implements Data{
    double ht;
    public CalVol(double r, double h){
        ht = h;
    public double volume(){
        return pi * rad * rad * ht;
    public void show(){;
        System.out.println("Height: " + ht);
        double v = volume();
        System.out.println("Volume of cylinder: " + v);
class Solve{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("Radius of cylinder: ");
        double r = Double.parseDouble(br.readLine());
        System.out.print("Height of cylinder: ");
        double h = Double.parseDouble(br.readLine());
        CalVol obj = new CalVol(r, h);;

3 replies on “ISC 2020 Computer Science Theory Data Interface Program”

Just replace import statement with:
import java.util.Scanner;
And BufferedReader line with:
Scanner in = new Scanner(;
And for input, you may use in.nextInt(), in.nextDouble(), in.nextLine(),;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.