Java Programming
Method Overloading
Java programming example for calculation of area using method overloading
By Geekboots
9/15/2021
0 views
method-overloading.javaJava
import java.io.*;
class formula {
/* First method with the name 'area' */
void area(int r) {
float a = 2 * (22/7) * r;
System.out.println("Circle Area: "+a);
}
/* Second method with the name 'area' */
void area(int height, int width) {
int a = height * width;
System.out.println("Rectangle Area: "+a);
}
}
class method_overloading {
public static void main(String args[ ]) {
formula ar = new formula();
ar.area(16);
ar.area(15,18);
}
}
/* Output */
Circle Area: 96.0
Rectangle Area: 270
Java programmingmethod overloadingarea calculation