Method Overloading in Java

class MethodOver
{
      int n1;
      int n2;

      MethodOver()
     {
           n1 = 10;
           n2 = 20;
     }

     void square()
    {
          System.out.println("\n\n\tThe Square is " + n1 * n2);
     }
    
     void square(int p1)
     {
          n1 = p1;
         System.out.println("\n\n\tThe Square is " + n1 * n2);
     }

    void square(int p1, int p2)
    {
         n1 = p1;
         n2 = p2;
         System.out.println("\n\n\tThe Square is " + n1 * n2);
    }

    public static void main(String args[])
   {
        MethodOver obj1 = new MethodOver();
        obj1.square();
        obj1.square(4);
        obj1.square(7,8);
   }
}

Comments

Popular posts from this blog

Shutdown Computer With Funny Reason

Hidden Attribute in javascript

Draw animated loading spinner canvas in Javascript