Problem Description: How to overload methods ? Solution: This example displays the way of…

Problem Description: How to overload methods ? Solution: This example displays the way of…

Problem Description:

How to overload methods ?

Solution:

This example displays the way of overloading a method depending on type and number of parameters.

classMyClass{ int height; MyClass(){ System.out.println(“bricks”); height=0; } MyClass(int i){ System.out.println(“Building new House that is ” + i+” feet tall”); height= i; } void info(){ System.out.println(“House is “+ height +” feet tall”); } void info(String s){ System.out.println(s+”: House is ” + height+” feet tall”); } } publicclassMainClass{ publicstaticvoid main(String[] args){ MyClass t=newMyClass(0); t.info(); t.info(“overloaded method”); //Overloaded constructor: newMyClass(); } }Result:

The above code sample will produce the following result.

Building new House that is 0 feet tall. House is 0 feet tall. Overloaded method: House is 0 feet tall. bricks