Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Java program method overloaing

PROGRAM:
To show method overloading .
/**
        * @Prof. Jayesh
        * Here method overloading is shown, differed in parameters.
        */

class ContainsMethods
{
void display(char gender)
{
     System.out.println(“gender= “+gender);
}
void display(char gender, int age)
{
     System.out.println(“Gender=” +gender + “,Age= “+age);
}
}
public class MethodOverloading {
   public static void main(String args[])
     {
          ContainsMethods obj = new ContainsMethods();
         obj.display(‘m’);
         obj.display(‘m’,60);
     }
}

OUTPUT:

gender= m
Gender=m,Age= 60


PROGRAM:
To show method overloading .
/**
        * @Prof. Jayesh
        * Here method overloading is shown.
* Differed in sequence of datatypes of parameters.
*/


class ContainsMethods
{
void display(char gender, int age)
{
     System.out.println(“gender= “+gender+“,Age= “+age);
}
void display(int age, char gender)
{
     System.out.println(“Age=” +age + “,Gender= “+gender);
}
}
public class MethodOverloading {
   public static void main(String args[])
     {
          ContainsMethods obj = new ContainsMethods();
         obj.display(‘m’,60);
         obj.display(60,‘m’);
     }
}

OUTPUT:
gender= m,Age= 60
Age=60,Gender= m


PROGRAM:
To show method overloading .
/**
        * @Prof. Jayesh
        * Here method overloading is shown, differed in datatypes of parameters.
        */

class ContainsMethods
{
void display(char a)
{
     System.out.println(a);
}
void display(int a)
{
     System.out.println(+a);
}
}
public class MethodOverloading {
   public static void main(String args[])
     {
          ContainsMethods obj = new ContainsMethods();
         obj.display(‘m’);
         obj.display(60);
     }
}

OUTPUT:

m
60