forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverloading.java
More file actions
22 lines (22 loc) · 780 Bytes
/
overloading.java
File metadata and controls
22 lines (22 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Program to demonstrate overloading in Java -
package overloading;
class SqRectArea {
public void Area(int a) {
System.out.println("The side of square = " + a);
System.out.println("The area of square = " + (a * a));
}
public void Area(int l, int b) {
System.out.println("Length = " + l);
System.out.println("Breadth = " + b);
System.out.println("The area of rectangle = " + (l * b));
}
}
public class Overloading {
public static void main(String[] args) {
// TODO Auto-generated method stub
SqRectArea sq = new SqRectArea(); // New object instantiation for square
sq.Area(5); // Calling function with 1 parameter
SqRectArea rect = new SqRectArea(); // New object instantiation for rectangle
rect.Area(10, 5); // Calling function with 2 parameters
}
}