Method Overloading

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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!