Get Website Learn Coding Tech Story

Java Programming Examples

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

Learn more about Method Overloading