-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAreaOfRectangle.java
More file actions
37 lines (30 loc) · 905 Bytes
/
Copy pathAreaOfRectangle.java
File metadata and controls
37 lines (30 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* 7. Make class "Rectangle" with attributes length and breadth. The class contains methods
computeArea and displayArea. Write a program with main method that creates two objects of
Rectangle class and find their areas and display area of larger rectangle. */
/*
* author : @pray3m
*/
class Rectangle{
int length;
int breadth;
Rectangle(int length,int breadth){
this.length=length;
this.breadth=breadth;
}
int computeArea(){
return length*breadth;
}
void displayArea(){
System.out.println("Area of larger rectangle is :"+computeArea());
}
}
public class AreaOfRectangle {
public static void main(String[] args) {
Rectangle r1=new Rectangle(4,5);
Rectangle r2=new Rectangle(6,8);
if(r1.computeArea() > r2.computeArea())
r1.displayArea();
else
r2.displayArea();
}
}