Call parameterized method define in a class from the main class



Define two classes and one main class. Each of the two classes
will have parameterized method. Try to call them from main class





Program:





class
Area


 {


  double CalArea(double l, float b)


    {


     return (l*b);


    }


 }





class
Volume


 {


  double CalVol(double l, float b, double h)


    {


     return (l*b*h);


    }


 }








class
Sk09


 {





  public static void main(String args[])


   {





    Area obj1=new Area();


    double a1= obj1.CalArea(5.5,6.5f);


    System.out.println("Area = "+a1);





    Volume obj2=new Volume();


    double v1= obj2.CalVol(5.5,6.5f,7.5);


    System.out.println("Volume =
"+v1);





    }


 }





Compile:


D:\>javac
Sk09.java


Run:


D:\>java
Sk09


Output:


Area =
35.75




Volume =
268.125


Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C