Turn Desktop View Off
by Dinesh Thakur

 

       class Average

         {
            int p,q,r;
            float a;
            Average()
               {
                   p=10;
                   q=20;
                   r=30;
               }
                  Average(int x)
                    {
                       p=x;
                       q=105;
                       r=160;
                    }
                       Average(int x,int y)
                          {
                              p=x;
                              q=y;
                              r=190;
                          }
                              Average(int x,int y, int  z)
                                  {
                                      p=x;
                                      q=y;
                                      r=z;
                                  }
                                      void getAverage()
                                         {
                                             a=(float)(p+q+r)/3;
                                             System.out.println("Averge of three variables is "+a);
                                         }
        }
                class AverageConstructorOverloading
                   {
                       public static void main(String args[])
                         {
                              Average Avg = new Average();
                              Average AvgSingle = new Average(200);
                              Average AvgDouble = new Average(405,102);
                              Average AvgThree = new Average(505,205,100);
                              Avg.getAverage();
                              AvgSingle.getAverage();
                              AvgDouble.getAverage();
                              AvgThree.getAverage();
                        }
                  }

Average of Three Variable using Constructor Overloading