Write a Java program to demonstrate method overloading with multiple parameters of the same data type
This Java program demonstrates method overloading in a class named Geometry, which calculates the area of rectangles and squares. Let's break down the code:
class Geometry { int area(int length, int width) { return length * width; } int area(int side) { return side * side; } public static void main(String[] args) { Geometry geo = new Geometry(); System.out.println("Area of Rectangle : " + geo.area(8, 3)); System.out.println("Area of Square : " + geo.area(7)); } }
Area of Rectangle : 24 Area of Square : 49
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions