-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaConstructorOverload.java
More file actions
65 lines (65 loc) · 1.45 KB
/
AreaConstructorOverload.java
File metadata and controls
65 lines (65 loc) · 1.45 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//Construct Overloading
import java.io.*;
class Rectangle
{
int length,breadth;
Rectangle(int l, int b)
{
length = l;
breadth = b;
}
int Area()
{
return length*breadth;
}
}
class Square
{
int side;
Square(int s)
{
side = s;
}
int Area()
{
return side*side;
}
}
class Circle
{
int radius;
Circle(int r)
{
radius = r;
}
double Area()
{
return (3.14*radius *radius) ;
}
}
class Construct
{
public static void main(String[] args)throws IOException
{
int re,sq;
double ci;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Enter the length and breadth of rectangle");
int l = Integer.parseInt(br.readLine());
int b = Integer.parseInt(br.readLine());
System.out.println("Enter the side of square");
int side=Integer.parseInt(br.readLine());
System.out.println("Enter the radius of circle");
int r=Integer.parseInt(br.readLine());
Rectangle rec=new Rectangle(l,b);
Square s=new Square(side);
Circle c=new Circle(r);
re = rec.Area();
sq = s.Area();
ci = c.Area();
System.out.println("Area of rectangle is "+re);
System.out.println("Area of square is "+sq);
System.out.println("Area of circle is "+ci);
}
}