-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructoroverloading.java
More file actions
63 lines (50 loc) · 1.48 KB
/
constructoroverloading.java
File metadata and controls
63 lines (50 loc) · 1.48 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
import java.util.Scanner;
class Circle{
double radius;
public Circle(){
radius=0;
}
public Circle(double radius){
this.radius=radius;
}
public double getArea(){
return Math.PI*radius*radius;
}
}
class Rectangle{
double width;
double height;
public Rectangle(){
width=0;
height=0;
}
public Rectangle(double width,double height){
this.width=width;
this.height=height;
}
public double getArea(){
return width*height;
}
}
public class constructoroverloading {
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
System.out.println("Enter the radius of the circle : ");
double radius = sc.nextDouble();
// two circle object
Circle c1=new Circle();
Circle c2=new Circle(radius);
System.out.println("First circle area = "+c1.getArea());
System.out.println("Second circle area = "+c2.getArea());
System.out.println("Enter the width of the rectangle : ");
double width = sc.nextDouble();
System.out.println("Enter the length of the rectangle : ");
double length = sc.nextDouble();
// two rectangle object
Rectangle r1=new Rectangle();
Rectangle r2=new Rectangle(width,length);
System.out.println("First rectangle area = "+r1.getArea());
System.out.println("Second rectangle area = "+r2.getArea());
sc.close();
}
}