/* program to illustrate Function Overloading */
package functionoverloading;
class Parent
{
public int Larger(int a,int b,int c)
{
return (a>b?(a>c?a:c):(b>c?b:c));
}
public int Larger(int a,int b)
{
return (a>b?a:b);
}
}
class Mainclass
{
public static void main(String[] args)
{
Parent p=new Parent();
System.out.println("Largest number is :"+p.Larger(2, 3));
System.out.println("Largest no is :"+ p.Larger(1, 5, 7));
}
}
output
Largest number is :3
Largest no is :7
package functionoverloading;
class Parent
{
public int Larger(int a,int b,int c)
{
return (a>b?(a>c?a:c):(b>c?b:c));
}
public int Larger(int a,int b)
{
return (a>b?a:b);
}
}
class Mainclass
{
public static void main(String[] args)
{
Parent p=new Parent();
System.out.println("Largest number is :"+p.Larger(2, 3));
System.out.println("Largest no is :"+ p.Larger(1, 5, 7));
}
}
output
Largest number is :3
Largest no is :7
No comments:
Post a Comment