Function overloading if we have more than one function having same name with different prototypes (parameters) then it is also called function overloading.
For Example:-
package myblogs;
/**
*
* @author pradeep
*/
class DemoOverloading
{
int height;
DemoOverloading()
{
System.out.println("Demo overloading");
height = 0;
}
DemoOverloading(int i)
{
System.out.println("Mobile phone tower Height "
+ i + " big tall");
height = i;
}
void info()
{
System.out.println("Building is" + height
+ " big tall");
}
void info(String s)
{
System.out.println(s + ": Building is "
+ height + " big tall");
}
}
public class MainDemoOverloading
{
public static void main(String[] args)
{
DemoOverloading t = new DemoOverloading(0);
t.info();
t.info("Function overloaded method");
// Function Overloaded constructor
new DemoOverloading();
}
}
Result: Output of this program is:
Mobile phone tower Height 0 big tall
Building is 0 big tall
Function overloaded method: Building is 0 big tall
Demo overloading
BUILD SUCCESSFUL (total time: 1 second)
Note: If you have any problem then reply me.
No comments:
Post a Comment