by Dinesh Thakur

 

class Average

          {
               int a,b,c;
               float av;
               Average()
                {
                   a=10;
               b=20;
               c=30;
            }
               Average(int x)
                  {
                     a=x;
                     b=40;
                     c=50;
                  }
                     Average(int x, int y)
                         {
                             a=x;
                         b=y;
                         c=50;
                         }
                         Average(int x,int y, int z)
                                     {
                                a=x;
                                b=y;
                                c=z;
                             }
                                void getAverage()
                                  {
                                      av=(float)(a+b+c)/3;
                                      System.out.println("Average of three variables is "+av);
                                  }
         }
                         class disc extends Average
                              {
                                  int d;
                                 disc()
                                     {
                                        super();
                                     }
                                        disc(int x)
                                           {
                                              super(x);
                                           }
                                              disc(int x, int y)
                                                   {
                                                      super(x,y);
                                                   }
                                                      disc(int x, int y, int z)
                                                       {
                                                          super(x,y,z);
                                                       }
                                                          void getdic()
                                                            {
                                                                d=b*b-4*a;
                                                                System.out.println("Discriminate of quadratic equation is"+d);
                                                            }
                               }
                                     class Averagesuper
                                        {
                                             public static void main(String args[])
                                              {
                                                  Average p=new Average();
                                                  Average q=new Average(15);
                                                  Average r=new Average(15,30);
                                                  Average s=new Average(15,30,45);
                                                 disc t=new disc();
                                                 disc u=new disc(15);
                                                 disc v=new disc(15,30);
                                                 disc w=new disc(15,30,45);
                                                 p.getAverage();
                                                 q.getAverage();
                                                  r.getAverage();
                                                 s.getAverage();
                                                 t.getdic();
                                                 u.getdic();
                                                 v.getdic();
                                                 w.getdic();
                                             }
                                                 }
Example of Super Class And Calculate Average of Three Variables