Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Pgm 4 || Program to add two integers and two float numbers. When no arguments are supplied, give a default value to calculate the sum. Use function overloading.

 public class Pgm4 {

void sum (int a, int b)

{

System.out.println("sum is="+(a+b)) ;

}

void sum (float a, float b)

{

System.out.println("sum is="+(a+b));

}

public static void main (String[] args)

{

Pgm4 cal = new Pgm4();

cal.sum (8,5); //sum(int a, int b) is method is called.

cal.sum (4.6f, 3.8f); //sum(float a, float b) is called.

}

}

Post a Comment

0 Comments