You are here:   HomeJava ProgrammingClasses in JavaExample of Super Class And Calculate Average of Three Variables
by Dinesh Thakur Category: Classes

 

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


Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article