Wed Sep 15 2021
Method Overloading
Java Programming2732 views
File Name: method-overloading.java
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
Reference:
Author:Geekboots