0% found this document useful (0 votes)
11 views2 pages

Omoops 8

The document outlines an experiment on method overloading in Java, specifically focusing on a class called Figure that calculates the area of various shapes. It includes a description of method overloading, how functions are identified at runtime, and provides sample code demonstrating the implementation. Students are expected to identify errors encountered during the experiment and propose solutions, with references for further reading included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Omoops 8

The document outlines an experiment on method overloading in Java, specifically focusing on a class called Figure that calculates the area of various shapes. It includes a description of method overloading, how functions are identified at runtime, and provides sample code demonstrating the implementation. Students are expected to identify errors encountered during the experiment and propose solutions, with references for further reading included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 8

Program on method overloading


Consider a class Figure and overload the function called area() to display the area of figures like
square,triangle, Rectangle and circle.
OBJECTIVE : To make students understand the basics of method overloading in java.
Description
What do you mean by Method overloading.
How overloading or functions are identified to be called at runtime.

CONCLUSION: Students are expected to List the error they are facing along with their solution
REFERENCES : https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html Java complete rwference
7th edition by Herbert Schildt Programming with JAVA by Balgurusamy

Program on method overloading


Consider a class Figure and overload the function called area() to display the area of figures like
square,triangle, Rectangle and circle.

public class Figure {


System.out.println(“Om Gaikwad”);
public void area(int side) {
System.out.println("Area of square: " + (side * side));
}

public void area(int base, int height) {


System.out.println("Area of triangle: " + (0.5 * base * height));
}
public void area(int length, int breadth) {
System.out.println("Area of rectangle: " + (length * breadth));
}
public void area(double radius) {
System.out.println("Area of circle: " + (3.14159 * radius * radius));
}

public static void main(String[] args) {


Figure figure = new Figure();

System.out.println("Square:");
figure.area(5);

System.out.println("\nTriangle:");
figure.area(4, 6);

System.out.println("\nRectangle:");
figure.area(3, 7);

System.out.println("\nCircle:");
figure.area(4.5);
}
}
Output:

You might also like