Overloaded methods allows to reuse the same method name in a class, but having different signature. Signature means one method varies with other method in terms of below points:

  • Number of arguments.
  • Types of arguments.
  • Order of arguments.

There are some rules as below:

  1. Overloaded methods must change the argument list.
  2. Overloaded methods can change the return type.
  3. Overloaded methods can be overloaded in the same class or subclass.
  4. Overloaded methods can declare new or broaded checked exception.

Overloaded methods can change the access modifier.

Some key points for above demo
  1. Shape class is having all constructors which different signatures.
  2. From main method different parameters has been passed and object has been created with different initializations.
Some key points for above demo
  1. ShapeOverload class is having methods, named Shape, with signatures.
  2. In main method object is getting created and with Shape method is getting called with different parameters.

    If you like the post then please socialize it. Happy Sharing. Loudly Subscribing.

Leave a Reply

Your email address will not be published. Required fields are marked *