Sunday, September 3, 2017

Method Overloading in Java

Here is a sample program that shows you how to perform method overloading in Java. The code is very simple and shows your one of the most important concepts of object oriented programming in Java.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


/**
 * 
 */
package method_overload;

/**
 * @author Jacob Samuel F. Pomperada
 * September 3, 2017
 * Sunday
 * Mandaluyong City, Metro Manila
 *
 */


class product {
private int a;
private int b;
    product()
{
a=5;
b=10;
}
    
   product(int x, int y)
    {
    a=x;
    b=y;
    }
   product(product z)
   {
  
  a= z.a;
  b= z.b;
   }
   
   
int compute()
{
return a*b;
}


}

public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
product test1 = new product();
product test2  = new product(2,3);
product test3  = new product(test2);
System.out.println();
        System.out.println("Method Overloading in Java");
        System.out.println();
        System.out.println("Written By Mr. Jake R. Pomperada, MAED-IT");
        System.out.println();
        System.out.println("The value is " +  test1.compute());
        System.out.println("The value is " +  test2.compute());
        System.out.println("The value is " +  test3.compute());
        System.out.println();
        System.out.println("End of Program");
        System.out.println();

}

}




No comments:

Post a Comment