You are here:   HomeJava ProgrammingJava MethodsDefining Methods in Java
by Dinesh Thakur Category: Java Methods

 

class Rectangle

            {
                int l,b,a;
                Rectangle()
                    {
                        l=5;     
                        b=3;
                    }
           
                    Rectangle(int x)
                      {
                          l=x;
                          b=3;
                      }
                          Rectangle(int x,int y)
                             {
                                 l=x;
                                 b=y;
                             }
                                void GetArea()
                                 {
                                      a=l*b;
                                      System.out.println("Area of Rectangle is : "+a);
                                 }
                   }
                                      class Volume extends Rectangle
                                          {
                                      int h,v;
                                      Volume()
                                      {
                                          super();
                                          h=30;
                                      }
                                                 Volume(int x)
                                      {
                                          super(x);
                                          h=30;
                                      }
                                          Volume(int x, int y)
                                                        {
                                                            super(x,y);
                                                h=30;
                                            }
                                                Volume(int x, int y, int z)
                                                    {
                                                       super(x,y);
                                                   h=z;
                                                }
                                                   int getVolume()
                                                      {
                                                         v=l*b*h;
                                                         return(v);
                                                       }
                                 }
                                      class SuperClassEx
                                         {
                                                         public static void main(String args[])
                                               {
                                                    Volume Vol = new Volume();
                                                    Volume Vol1=new Volume(5);
                                                    Volume Vol2=new Volume(5,2);
                                                    Volume Vol3=new Volume(5,3,2);
                                                    System.out.println("Volume of First Rectangle is : "+Vol.getVolume());
                                                    System.out.println("Volume of Second Rectangle is : "+Vol1.getVolume());
                                                    System.out.println("Volume of Third Rectangle is : "+Vol2.getVolume());
                                                    System.out.println("Volume of Fourth Rectangle is : "+Vol3.getVolume());
                                               }
                                        }

Example of Super Method in Java



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