UrbanPro
true
default_background

Take Class 7 Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Function Overloading in Java using If statement

Vishwambhar nath S.
2 days ago 0 0

/*

Design a class to overload a function volume() as follows:

(i) double volume(double r)

(ii)double volume(double h, double r)

(iii) double volume(double l, double b, double h)

 */

import java.io.*;

import java.util.*;

 

class fun_overloading_if

{   Scanner in = new Scanner(System.in);

    //  InputStreamReader isr = new InputStreamReader(System.in);

    // BufferedReader in = new BufferedReader(isr);

    void main() throws IOException

    {   int choice;

        double v,r,h,l,b;

        System.out.print("1. Sphere ");

        System.out.print("2. Cylinder: ");

        System.out.print("3. Cuboid: ");

        System.out.print("Enter Choice: ");

        choice = in.nextInt();

        if (choice==1)

        {

            System.out.print("Enter r: ");

            r = in.nextInt();

            v=volume(r);

            System.out.print("Volume of sphere = "+v);

        }

        else if (choice==2)

        {

            System.out.print("Enter r: ");

            r = in.nextInt();

            System.out.print("Enter h: ");

            h = in.nextInt();

            v=volume(r,h);

            System.out.print("Volume of cylinder = "+v);

        }

        else if (choice==3)

        {

            System.out.print("Enter l: ");

            l = in.nextInt();

            System.out.print("Enter b: ");

            b = in.nextInt();

            System.out.print("Enter h: ");

            h = in.nextInt();

            v=volume(l,b,h);

            System.out.print("Volume of cuboid = "+v);

        }

    }

 

    double volume(double r)

    {

        return 4.0 / 3 * 22.0 / 7 * r * r * r;

    }

 

    double volume(double h, double r)

    {

        return 22.0 / 7 * r * r * h;

    }

 

    double volume(double l, double b, double h)

    {

        return l * b * h;

    }

}

0 Dislike
Follow 1

Please Enter a comment

Submit

Looking for Class 7 Tuition ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Class 7 Tuition Classes?

The best tutors for Class 7 Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take Class 7 Tuition with the Best Tutors

The best Tutors for Class 7 Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more