I am a Java newbie, and they have just recently taught us abstract classes and inheritance. While I was practising, I wondered whether I can make multiple instances of the same abstract method in different classes. (We didn't go that far, and my knowledge about this is what I have gleaned during our professor writing code in front of us.) My curiosity led me to write this code, that I have posted here. It compiles and runs fine, AFAIK; but, I would like this to be simpler and more succinct, if possible. import java.math.*;import java.util.*;abstract class Figure{                        // I cant have 2 constructors with same      parameters it seems.                        // so side1 has to float otherwise it creates an ambiguity error with                         //radius    final double PI = 3.14;    double side, height,base;    int radius;    float side1;    Figure(float s1)    {        side1 = s1;//cube    }    Figure(double h1, int r1)// cone uses side instead of height to resolve ambiguity    {        height = h1;//cone         radius = r1;    }    Figure(int r1)    {        radius = r1;//sphere    }    Figure(int r1,double h1)    {        radius =r1;        height = h1;//cylinder    }    Figure(double h1,double b1)    {        base = b1;        height = h1;//pyramid    }    abstract double areaCalculator();}class Cube extends Figure{    double result;    Cube(float s1)    {        super(s1);    }    double areaCalculator()    {        result = 6 * Math.pow(side1,2);         return result;    }}class Cone extends Figure{    double result;    Cone(double h1, int r1)    {        super(h1,r1);    }    double areaCalculator()    {        result = (PI * height * radius) + (PI * Math.pow(radius,2));        return result;    }}class Sphere extends Figure{    double result;    Sphere(int r1)    {        super(r1);    }    double areaCalculator()    {        result = PI * 4.0 * Math.pow(radius,2);        return result;    }}class Cylinder extends Figure{    double result;    Cylinder(int r1, double h1)    {        super(r1, h1);    }    double areaCalculator()    {        result = (2.0 * PI * Math.pow(radius,2)) + (2.0 * PI * radius * height);        return result;    }}class Pyramidsqbase extends Figure{    double result;    Pyramidsqbase(double b1, double h1)    {        super(h1,b1);    }    double areaCalculator()    {        result = Math.pow(base,2) + (2.0 * base * height);        return result;    }}class Newsurfaceareacalc2{    public static void main(String args[])    {        double result,side, height, base;        int choice, radius;        float side1;        Scanner sc = new Scanner(System.in);        System.out.println(Surface area Calculator:);        System.out.println(1 for cube, 2 for cone, 3 for sphere, 4 for cylinder, 5 for square-base pyramid.);            choice = sc.nextInt();        switch(choice)        {            case 1: System.out.println(Enter value of side of cube:);//cube                side1 = sc.nextFloat();                Cube c1 = new Cube(side1);                result = c1.areaCalculator();                System.out.println(Result is + result);                    break;            case 2: System.out.println(Enter value of radius of cone:);//cone                radius = sc.nextInt();                System.out.println(Enter value of height of cone:);                height = sc.nextDouble();                Cone c2 = new Cone(height, radius);                result = c2.areaCalculator();                System.out.println(Result is + result);                break;            case 3: System.out.println(Enter value of radius of sphere:);//sphere                radius = sc.nextInt();                Sphere s2 = new Sphere(radius);                result = s2.areaCalculator();                System.out.println(Result is + result);                break;            case 4: System.out.println(Enter value of radius of cylinder:);//cylinder                radius = sc.nextInt();                System.out.println(Enter value of of height of cylinder:);                height = sc.nextDouble();                Cylinder c3 = new Cylinder(radius, height);                result = c3.areaCalculator();                System.out.println(Result is + result);                break;            case 5: System.out.println(Enter value of base in pyramid);//pyramid                base = sc.nextDouble();                System.out.println(Enter value of height in pyramid:);                height = sc.nextDouble();                Pyramidsqbase p1 = new Pyramidsqbase(base, height);                result = p1.areaCalculator();                System.out.println(Result is + result);                break;            default: System.out.println(Error.);        }    }}
Calculator for the area of various 3D figures, using abstract classes and inheritance
java;beginner;calculator;inheritance